Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js how to filter range in place

// @ts-check

let arr = [5, 3, 8, 1, 9, 2, 4, 15, 18, 42, 39];

function filterRangeInPlace(arr, a, b) {
  for (let i = 0; i < arr.length; ++i) {
    if (a > arr[i] || arr[i] > b) {
      arr.splice(i, 1);
      i--; // since the length of the array has changed
    }
  }
}
filterRangeInPlace(arr, 1, 4);

console.log(arr);
Comment

PREVIOUS NEXT
Code Example
Javascript :: reset reactive state vue 3 
Javascript :: sequilze REACTJS 
Javascript :: ?? javascript 
Javascript :: javascript line chart 
Javascript :: Don’t Use If-Else and Switch in JavaScript, Use Object Literals 
Javascript :: reduce in js 
Javascript :: jquery check valid link 
Javascript :: react route path 
Javascript :: javascript mover 
Javascript :: jquery remove all alerts 
Javascript :: javascript constructor 
Javascript :: how to add attribute in a element 
Javascript :: react native skeleton 
Javascript :: how to set variable in discord.js 
Javascript :: jason arraylist 
Javascript :: how to use location.pathname 
Javascript :: minified react error #200 
Javascript :: javascript Rename in the import file 
Javascript :: setinterval on and off 
Javascript :: js some 
Javascript :: js spread parameters 
Javascript :: how to sent react from data in mongodb 
Javascript :: javascript constants 
Javascript :: validatorjs number 
Javascript :: define function 
Javascript :: web3.js tutorials 
Javascript :: module imports as default 
Javascript :: js Destructuring arrays and objects 
Javascript :: js electron setup 
Javascript :: base64 to base64url 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =