Created
August 20, 2023 18:17
-
-
Save artidataio/afb77c17ce20fda24538fa44cf6c1585 to your computer and use it in GitHub Desktop.
Twitter thing
This file contains hidden or 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 computeClosestToZero(arr: number[]) { | |
return arr.length > 0 | |
? arr.sort((a, b) => { | |
let absDiff = Math.abs(a) - Math.abs(b); | |
return absDiff === 0 ? b - a : absDiff; | |
})[0] | |
: 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment