Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def requestMatching(pros, distances, travelPreferences)
- pros_length = pros.length
- matching_score = Array.new(pros_length) {Array.new}
- non_matching_score = Array.new(pros_length) {Array.new}
- final_array = Array.new
- x = 0
- y = 0
- z = 0
- while (x < pros_length)
- if distances[x] <= travelPreferences[x] then
- matching_score[y][0] = distances[x]
- matching_score[y][1] = pros[x]
- y = y + 1
- else
- non_matching_score[z][0] = distances[x] - travelPreferences[x]
- non_matching_score[z][1] = pros[x]
- z = z + 1
- end
- x = x + 1
- end
- matching_score = matching_score.delete_if {|elem| elem.flatten.empty?}
- matching_score = matching_score.sort
- non_matching_score = non_matching_score.delete_if {|elem| elem.flatten.empty?}
- non_matching_score = non_matching_score.sort
- x = 0
- y = 0
- array_length = matching_score.length
- while (y < array_length)
- final_array[x] = matching_score[y][1]
- x = x + 1
- y = y + 1
- end
- array_length = 5 - final_array.length
- y = 0
- while (y < array_length and y <= non_matching_score.length - 1)
- final_array[x] = non_matching_score[y][1]
- x = x + 1
- y = y + 1
- end
- return final_array
- end
Advertisement
Add Comment
Please, Sign In to add comment