Created
April 13, 2020 20:15
-
-
Save Nicknyr/b0363ca45c02375dd2ee3ad96c2110ab to your computer and use it in GitHub Desktop.
CodeSignal - Concatenate 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
/* | |
Given two arrays of integers a and b, obtain the array formed by the elements of a followed by the elements of b. | |
Example | |
For a = [2, 2, 1] and b = [10, 11], the output should be | |
concatenateArrays(a, b) = [2, 2, 1, 10, 11]. | |
*/ | |
function concatenateArrays(a, b) { | |
/* | |
Solving with a for loop | |
for(let i = 0; i < b.length; i++) { | |
a.push(b[i]); | |
} | |
return a; | |
*/ | |
// Solving with the spread operator | |
let concatArr = [...a, ...b]; | |
return concatArr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment