Emperor01 / JSlearn

all my practical trainings
0 stars 0 forks source link

array = array [ elements only in range num1 <= array[i] <= num2] #14

Open Emperor01 opened 6 years ago

Emperor01 commented 6 years ago

'use strict';

function filterInRange (arr, a, b) {

return arr.filter(function (item) {return item >= a && item <= b}); }

var arr = [5, 3, 8, 1];

var num1 = +prompt('input number 1', ''); var num2 = +prompt('input number 2', '');

arr = filterInRange(arr, num1, num2);

alert( arr ); // массив изменился: остались [3, 1]