Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active October 6, 2022 11:58
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 McLarenCollege/a35d471590895dbca6e2d4334722dca0 to your computer and use it in GitHub Desktop.
Save McLarenCollege/a35d471590895dbca6e2d4334722dca0 to your computer and use it in GitHub Desktop.
Exercise : Zip It

Zip It

Write a function called zipIt that accepts two already sorted arrays and returns a new array which contains all the elements present in both the arrays in a sorted order.

  • Note: Do not use a sorting algorithm

Eg.

zipIt([1,5,9,10], [2,4,7])

will return [1,2,4,5,7,9,10]

CODE TEMPLATE


function zipIt(arr1,arr2){
// write your code here
}
console.log(zipIt([1, 5, 9, 10], [2, 4, 7])); // should return `[1, 2, 4, 5, 7, 9,10]`

console.log(zipIt([1, 2, 3, 4], [4, 5, 6, 7])); // should return `[1, 2, 3, 4, 4, 5, 6, 7]`

Please watch this Video for a hint for the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment