fork download
  1. function filter (arr, fn) {
  2. var newArr = [];
  3.  
  4. for (var i = 0; i < arr.length; i++) {
  5. if (fn(arr[i])) {
  6. newArr.push(arr[i]);
  7. }
  8. };
  9. return newArr;
  10. }
  11.  
  12.  
  13. var input = [1, 2, 3, 4, 5, 6];
  14. function isEven(x) { return x % 2 == 0; } // проверяет на четность
  15. console.log(filter(input, isEven)); // [2, 4, 6]
  16.  
  17. console.log(input); // [1, 2, 3, 4, 5, 6]
Runtime error #stdin #stdout #stderr 0.48s 321920KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
js: uncaught JavaScript runtime exception: ReferenceError: "console" is not defined.