Leetcode 1365. How Many Numbers Are Smaller Than the Current Number
1 2 3 4 5 6 7 | var smallerNumbersThanCurrent = function(nums) { let result = [] for(i = 0; i < nums.length; i++) { result.push(nums.filter(num => num < nums[i]).length) } return result }; | cs |
1 2 3 | var smallerNumbersThanCurrent = function (nums) { return nums.map(n => nums.reduce((a, b) => a + (n > b ? 1 : 0), 0)) }; | cs |