Last active
September 21, 2019 08:14
-
-
Save narutaro/a2d31ea455b2a40117bed13fb07acc1d to your computer and use it in GitHub Desktop.
Filter an array based on odd or even
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
let ary = [ | |
'0:00', | |
'0:30', | |
'1:00', | |
'1:30', | |
'2:00', | |
'2:30', | |
'3:00', | |
'3:30', | |
'4:00', | |
'4:30', | |
'5:00', | |
'5:30', | |
'6:00', | |
'6:30', | |
'7:00', | |
'7:30', | |
] | |
let onlyOdd = ary.filter((time, idx) => idx % 2 != 0 ) | |
let onlyEven = ary.filter((time, idx) => idx % 2 == 0 ) | |
console.log('Odd', onlyOdd) | |
console.log('Even', onlyEven) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment