Показать сообщение отдельно
  #7 (permalink)  
Старый 18.02.2020, 15:07
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,068

Сообщение от 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)));
Ответить с цитированием