Skip to content

Instantly share code, notes, and snippets.

@jacoborus
Last active July 23, 2019 14:10
Show Gist options
  • Save jacoborus/a0be1982b2cbb0b6f837417e6558d750 to your computer and use it in GitHub Desktop.
Save jacoborus/a0be1982b2cbb0b6f837417e6558d750 to your computer and use it in GitHub Desktop.
closerToZero
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