Created
July 23, 2015 13:05
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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