Escape The Ghosts LeetCode solution in JavaScript
1var escapeGhosts = function (ghosts, target) {2const getDistance = (target, source = [0, 0]) => {3return Math.abs(target[0] - source[0]) + Math.abs(target[1] - source[1]);4};5const timeTakenByMe = getDistance(target);6let timeTakenByGhosts = Infinity;7for (let ghost of ghosts) {8timeTakenByGhosts = Math.min(timeTakenByGhosts, getDistance(target, ghost));9}10return timeTakenByGhosts > timeTakenByMe;11};