Created
June 29, 2017 21:30
-
-
Save fernandozamoraj/62435d1291bcdcbbafe3c26cda6d612d to your computer and use it in GitHub Desktop.
Filter using javascript
This file contains hidden or 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
var numbers = [1,2,3,6,8,3,4,6,78,10,11,9,1,3,4] | |
function filter(arr, filterCheck){ | |
var newArray = [] | |
for(var i=0;i<arr.length;i++){ | |
if(filterCheck(arr[i])){ | |
newArray.push(arr[i]) | |
} | |
} | |
return newArray; | |
} | |
var filtered = filter(numbers, (x) => x > 6) | |
console.log(filtered) | |
var evenNumbers = filter(numbers, (x) => (x % 2 === 0)) | |
console.log(evenNumbers) | |
var students = [{age: 13}, {age: 10}, {age: 9}] | |
students = filter(students, (x) => x.age > 10) | |
console.log(students) | |
function getEventNumbers(arr){ | |
return filter(arr, x => x % 2) | |
} | |
console.log(getEventNumbers([1,2,3,4,5,6,7,8,9])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment