Heaters LeetCode solution in JavaScript
1var findRadius = function (houses, heaters) {2houses.sort((a, b) => a - b);3heaters.sort((a, b) => a - b);4let heaterPos = 0;5const getRadius = (house, pos) => Math.abs(heaters[pos] - house);67return houses.reduce((radius, house) => {8while (9heaterPos < heaters.length &&10getRadius(house, heaterPos) >= getRadius(house, heaterPos + 1)11)12heaterPos += 1;1314const currentRadius = getRadius(house, heaterPos);15return Math.max(radius, currentRadius);16}, 0);17};