Created
August 28, 2017 23:31
-
-
Save claudiainbytes/4d343697dbb99bf3c68b861a66b8572b to your computer and use it in GitHub Desktop.
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 sampleArray = [0,0,7]; | |
var incrementLastArrayElement = function(_array) { | |
var newArray = []; | |
// Your code should make newArray equal to an array that has the same | |
// values as _array, but the last number has increased by one. | |
// For example: | |
// _array = [1, 2, 3]; | |
// turns into: | |
// newArray = [1, 2, 4]; | |
// Your code goes in here! | |
_array.forEach(function(e, i, a){ | |
(i == (a.length-1)) ? e++ : e ; | |
newArray.push(e); | |
}); | |
// Don't delete this line! | |
return newArray; | |
}; | |
// Did your code work? The line below will tell you! | |
console.log(incrementLastArrayElement(sampleArray)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment