Created
July 6, 2017 17:46
-
-
Save prof3ssorSt3v3/17c882203bd9d433137a414f7bb544a8 to your computer and use it in GitHub Desktop.
Sample of the Array filter( ) method.
This file contains 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
//Array filter() method | |
let numbers = [23, 45, 14, 66, 94, 33, 4, 9]; | |
let breakPoint = 30; | |
let smallNumbers = numbers.filter(function(num){ | |
return num < breakPoint; | |
}); | |
let bigNumbers = numbers.filter(checkBig); | |
function checkBig(num){ | |
return num > breakPoint; | |
} | |
let oddNumbers = numbers.filter(function(num){ | |
//let remainder = num % 2; | |
//0, 1, 10, 11, 100, 101, 110, 111, 1000 | |
//0, 1, 2, 3, 4, 5, 6, 7, 8 | |
return num & 1; | |
}); | |
console.log('\nSmaller than 30:', smallNumbers); | |
console.log('\n Larger than 30:', bigNumbers); | |
console.log('\n Odd numbers:', oddNumbers); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment