Skip to content

Instantly share code, notes, and snippets.

@claudiainbytes
Created August 28, 2017 23:31
Show Gist options
  • Save claudiainbytes/4d343697dbb99bf3c68b861a66b8572b to your computer and use it in GitHub Desktop.
Save claudiainbytes/4d343697dbb99bf3c68b861a66b8572b to your computer and use it in GitHub Desktop.
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