Last active
July 23, 2019 14:10
-
-
Save jacoborus/a0be1982b2cbb0b6f837417e6558d750 to your computer and use it in GitHub Desktop.
closerToZero
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function outputTemp (tempRow) { | |
return tempRow | |
.split(' ') | |
.map(n => Number(n)) | |
.reduce((min, val) => { | |
const abs = Math.abs(val) | |
const pos = val >= 0 | |
if ((pos && abs === min.abs) || abs < min.abs) { | |
return { val, abs } | |
} | |
return min | |
}, | |
{ | |
val: Infinity, | |
abs: Infinity | |
}) | |
.val | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment