Find the Smallest Divisor Given a Threshold LeetCode solution in JavaScript
1var smallestDivisor = function (nums, threshold) {2let left = 1;3let right = nums.reduce((r, x) => Math.max(r, x), 0);45while (left <= right) {6const div = Math.floor((left + right) / 2);7const sum = nums.reduce((r, x) => r + Math.ceil(x / div), 0);89if (sum <= threshold) {10right = div - 1;11} else {12left = div + 1;13}14}1516return left;17};