Car Fleet LeetCode solution in JavaScript
1var carFleet = function (target, position, speed) {2for (let i = 0; i < position.length; i++) {3position[i] = [target - position[i], speed[i]];4}5position.sort((a, b) => {6return a[0] - b[0];7});8let count = 1,9prev = position[0][0] / position[0][1];10for (let i = 1; i < position.length; i++) {11// if the time taken is longer then it will cause another fleet12if (position[i][0] / position[i][1] > prev) {13count++;14prev = position[i][0] / position[i][1];15}16}1718return count;19};