Created
October 13, 2016 13:59
-
-
Save hulkish/0dedaff5572a0f41e6a361a64ff0084a to your computer and use it in GitHub Desktop.
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 beforeInts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 112, 113]; | |
let afterInts = evenify(beforeInts); | |
console.log('beforeInts: ' + beforeInts); | |
console.log('afterInts: ' + afterInts); | |
function evenify(ints, currentIndex = 0, evenInts = []) {// es6 feature for default argument values | |
let currentInt = ints[currentIndex]; | |
if (currentInt % 2 === 0) { | |
evenInts.push(currentInt); | |
} | |
if (++currentIndex >= ints.length) { | |
return evenInts; | |
} | |
return evenify(ints, currentIndex, evenInts) ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment