Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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