Skip to content

Instantly share code, notes, and snippets.

@vadimkorr
Created March 10, 2018 17:33
Show Gist options
  • Save vadimkorr/15bca86ea34608ed9de51862769d8930 to your computer and use it in GitHub Desktop.
Save vadimkorr/15bca86ea34608ed9de51862769d8930 to your computer and use it in GitHub Desktop.
// 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