Skip to content

Instantly share code, notes, and snippets.

@Shavindra
Created April 24, 2020 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shavindra/9b589aa9378c3eeeebf4d40e896e6d11 to your computer and use it in GitHub Desktop.
Save Shavindra/9b589aa9378c3eeeebf4d40e896e6d11 to your computer and use it in GitHub Desktop.
Value closest to zero
const sortedTemps = temps.sort((a, b) => Math.abs(a) - Math.abs(b) || b - a);
const result = sortedTemps[0] || 0;
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment