re: Challenge: Get Closest Number in an Array VIEW POST

FULL DISCUSSION
 

JS:

const nums = [100, 200, 400, 800, 1600, 3200, 6400, 128000];
const givenNum = 900;

nums
.map(n => ({n, d: Math.abs(n-givenNum)}))
.sort((n1, n2) => Math.sign(n1.d - n2.d))[0].n

code of conduct - report abuse