Created
May 23, 2020 05:25
-
-
Save hebertcisco/25707f82a8d627c60181b6ef8d6b8df9 to your computer and use it in GitHub Desktop.
The filter() method creates a new array with all the elements that have passed the test implemented by the provided function. Filter only the even numbers of the Fibonacci sequence:
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
const fibonacciSequence = [ | |
0, | |
1, | |
1, | |
2, | |
3, | |
5, | |
8, | |
13, | |
21, | |
34, | |
55, | |
89, | |
144, | |
233, | |
377, | |
610, | |
987, | |
1597, | |
2584, | |
4181, | |
6765, | |
10946, | |
17711, | |
28657, | |
46368, | |
75025, | |
121393, | |
196418, | |
317811, | |
]; | |
const pair = (n) => n % 2 === 0; | |
const numsPair = fibonacciSequence.filter(pair); | |
console.log(`Array with even numbers: ${numsPair}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment