getClosestToZero (9, 5, -4, -9) // -4
. function getClosestToZero() {
let numbers = Array.prototype.slice.call(arguments)
return numbers.reduce((prev, curr) =>
Math.abs(prev) > Math.abs(curr)
? curr : prev
, +Infinity)
}
jsfiddle.net/x2erL66q