Created
March 14, 2016 19:28
-
-
Save jonathanbarton/9150f9b2c9a2db0938b6 to your computer and use it in GitHub Desktop.
simple_programming_problem_lists_strings_10: Alternating Arrays
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
var arr1 = ['a','b','c']; | |
var arr2 = ['r','t','z','f']; | |
var alternateArray = function(a, b) { | |
var i = 0, result = []; | |
while(a[i] || b[i]) { | |
if(a[i]){ | |
result.push(a[i]); | |
} | |
if(b[i]){ | |
result.push(b[i]); | |
} | |
i++; | |
} | |
console.log(result); | |
return result; | |
}; | |
alternateArray(arr1,arr2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment