Сообщение от Nexus
|
трудночитаемый
|
const arrayNumbers = [-5, 0, 5, 10, 15, 20, 25, 30, 35];
const n = 23.45;
const k = 11.38;
/*const res = (a, b, c) => (b = a.map(a => Math.abs(a - b)), c = Math.min(...b), b = b.findIndex(a => a === c), a[b]);*/
const search = (array, number) => {
const arrayAbs = array.map(value => Math.abs(value - number));
const minArrayAbs = Math.min(...arrayAbs);
const indexMinArrayAbs = arrayAbs.findIndex(value => value === minArrayAbs);
return array[indexMinArrayAbs]
}
/*const fn = res.bind("",arrayNumbers);*/
const fn = search.bind("",arrayNumbers);
alert(JSON.stringify([n, k].map(fn)));