Created
March 10, 2018 17:33
-
-
Save vadimkorr/15bca86ea34608ed9de51862769d8930 to your computer and use it in GitHub Desktop.
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
// Merge two sorted arrays | |
let a = [2, 5, 7, 9, 10] | |
let b = [1, 3, 8, 10, 11, 15] | |
let c = [] | |
let i = j =0 | |
while (i < a.length && j < b.length) { | |
if(a[i] < b[j]) { | |
c.push(a[i++]) | |
} else { | |
c.push(b[j++]) | |
} | |
} | |
while (i < a.length) { | |
c.push(a[i++]) | |
} | |
while (j < b.length) { | |
c.push(b[j++]) | |
} | |
console.log(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment