Skip to content

Instantly share code, notes, and snippets.

@ihorkatkov
Created July 23, 2015 13:05
Show Gist options
  • Save ihorkatkov/b672f4c980e55d8d2069 to your computer and use it in GitHub Desktop.
Save ihorkatkov/b672f4c980e55d8d2069 to your computer and use it in GitHub Desktop.
[JS] Фильтр диапазона. Функция filterRange(arr, a, b), принимает массив чисел arr и возвращает новый массив, который содержит только числа из arr из диапазона от a до b. То есть, проверка имеет вид a ≤ arr[i] ≤ b.
function filterRange(arr, a, b) {
var i = 0;
var result = [];
for (i = 0; i<arr.length; i++) {
if (arr[i] >= a && arr[i] <= b) {
result.push(arr[i]);
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment