IT
Size: a a a
IT
T
В
T
В
T
return Object.entries(points).sort(([_, l], [__, r]) => Math.abs(l-n) - Math.abs(l-r))[0][0];
L
const points = {
foo: 10,
bar: 8,
xyz: 3
}
function getClosePoint(obj, n) {
return Object.entries(obj).sort((l, r) => (r[1]-n) - (l[1]-n))[0][0]
}
getClosePoint(points, 9)
T
const points = {
foo: 10,
bar: 8,
xyz: 3
}
function getClosePoint(obj, n) {
return Object.entries(obj).sort((l, r) => (r[1]-n) - (l[1]-n))[0][0]
}
getClosePoint(points, 9)
L
L
L
T
getClosePoint(-10);
L
T
r-n
во втором absT
L
r-n
во втором absIT
T
Object.entries(points).reduce((res, [key, num]) => (res.diff > Math.abs(num - n)) ? {diff: Math.abs(num - n), key} : res, {diff: Infinity, key: ''})
IT