Good day! Please tell me how to search for an approximate number. Suppose there is an array [1 5 2 4 9], the required number is 6, if it is not in the array, then you need to find a close smaller one (4). Search is carried out in the array of old in the field of olds.
<input type="text" placeholder="Возраст" id="age"><br> <input type="text" placeholder="Зрелость" id="maturity"><br> <button onclick="inputData()">Обучить</button> <hr> <input type="text" placeholder="Введите свой возраст" id="myAge"><br> <button onclick="myMaturity()">Узнать свою зрелость</button> var old = [ { olds: 1, mature: "Молодой" }, { olds: 30, mature: "Зрелый" }, { olds: 60, mature: "Старый" } ]; function inputData() { var a = document.getElementById('age').value; var b = document.getElementById('maturity').value; old.push({ olds: a, mature: b }); console.log(old); } function myMaturity () { var a1 = document.getElementById('myAge').value; for (var key in old) { if (old[key].olds <= a1) { console.log(old[key].mature); } } }