This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Problem Set below: | |
| // Task: Implement a class named 'RangeList' | |
| // A pair of integers define a range, for example: [1, 5). This range includes integers: 1, 2, 3, and 4. | |
| // A range list is an aggregate of these ranges: [1, 5), [10, 11), [100, 201) | |
| /* | |
| RangeList is a strict ordered range list: | |
| 1. For any [a, b] in RangeList, a < b | |
| 2. For any [a1, b1], [a2, b2] in RangeList with index i, j, given i < j, a1 < b1 < a2 < b2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const assignVehicles = (vehicles, drivers) => { | |
| vehicles = JSON.parse(JSON.stringify(vehicles)) | |
| drivers = JSON.parse(JSON.stringify(drivers)) | |
| vehicles.sort((a, b) => a.year - b.year) | |
| drivers.sort((a, b) => b.age - a.age) | |
| // console.log('Sorted:', vehicles, drivers) | |
| let result = { | |
| vehicles: {}, | |
| drivers: {} |
NewerOlder