Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js how to filter range imutable array

// @ts-check
let arr = [5, 3, 8, 1];

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

let filtered = filterRange(arr, 1, 4);

console.log(filtered); // => [ 3, 1 ]
console.log(arr); // => [ 5, 3, 8, 1 ]
 
PREVIOUS NEXT
Tagged: #js #filter #range #imutable #array
ADD COMMENT
Topic
Name
8+1 =