Escape The Ghosts LeetCode solution in JavaScript

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

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0