JS Como filtrar o alcance no lugar

// @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);
Condemned Corncrake