Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
var input = [1, 2, 3, 4, 5, 6];
function isEven(x) { 
    return x % 2 === 0; 
} // проверяет на четность
function filter(fn, array) {
    var newArray = [];
    
    array.forEach(function(element) {
        if (fn(element) === false) {
            array.splice(array.indexOf(element), 1);
        }
    });
    
    return array;
}
console.log(filter(isEven, input)); // [2, 4, 6]
console.log(input); // expected: [1, 2, 3, 4, 5, 6]
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers