script.js 297 B

123456789101112131415
  1. let arr1 = [1, 2, 3, 4, 5];
  2. function myFilter (arr, func) {
  3. let result = [];
  4. for (let item of arr){
  5. if(func(item)){
  6. result.push(item);
  7. }
  8. }
  9. console.log(result);
  10. return result;
  11. }
  12. myFilter(arr1, x => x<2);
  13. myFilter(['cold', 'wanna sleep'], confirm);