Skip to content

Instantly share code, notes, and snippets.

@artidataio
Created August 20, 2023 18:17
Show Gist options
  • Save artidataio/afb77c17ce20fda24538fa44cf6c1585 to your computer and use it in GitHub Desktop.
Save artidataio/afb77c17ce20fda24538fa44cf6c1585 to your computer and use it in GitHub Desktop.
Twitter thing
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