Skip to content

Instantly share code, notes, and snippets.

@LESTADru
Created February 4, 2014 17:50
Show Gist options
  • Save LESTADru/8808750 to your computer and use it in GitHub Desktop.
Save LESTADru/8808750 to your computer and use it in GitHub Desktop.
функция filterRangeInPlace(arr, a, b), которая получает массив с числами arr и удаляет из него все числа вне диапазона a..b.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>функция filterRangeInPlace(arr, a, b),
которая получает массив с числами arr и удаляет из него
все числа вне диапазона a..b.</title></head>
<body>
<script>
'use strict'
function filterRangeInPlace(arr, a, b){
for(var i=0;i<arr.length;i++){
if(a<=arr[i] && arr[i]<=b){
arr.splice(i, 1);
i--;
}
}
}
var arr = [5, 3, 8, 1];
alert(arr);
filterRangeInPlace(arr, 1, 4);
alert(arr);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment