Skip to content

Instantly share code, notes, and snippets.

@Nicknyr
Created April 13, 2020 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nicknyr/b0363ca45c02375dd2ee3ad96c2110ab to your computer and use it in GitHub Desktop.
Save Nicknyr/b0363ca45c02375dd2ee3ad96c2110ab to your computer and use it in GitHub Desktop.
CodeSignal - Concatenate Arrays
/*
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