Merge Two Sorted Arrays JavaScript

preview_player
Показать описание
In this video I explain what merge sort is. I then teach you how to implement it using JavaScript.

Here's the coded version:
Here's a Medium article covering the same thing:
Check out my LinkedIn!
Рекомендации по теме
Комментарии
Автор

I rarely comment on Youtube, and I know this is a pretty old video, but for the first time I could understand it!
Thanks, bro, God bless!

tiagoaguiar
Автор

Thank you, I didnt understand this by watching those Harvard guys from CS50 but I understood you very well

Zeraltz
Автор

you can optimize this:
singleSorted.push(arrA[0]);
arrA.shift();

to


because shift return cut off first element.
and same with arrB

for the rest, thanks, that was helpful

alexgolubev
Автор

You're brilliant, thank you so much!

OscarRodriguez-bcol
Автор

helpful video.. keep up the good work!

eatcoderepeat
Автор

I think we can make even more compact taking cue from Alex.
function merge(arrA, arrB) {
let singleSorted = [];
while(arrA.length && arrB.length) {
arrA[0] < arrB[0] ? :
}
return singleSorted.concat(arrA, arrB);
}

MrGodman
Автор

Hey Joe Begley Codes -- awesome video. Clear, descriptive, and to the point. Writing a merge sort function with JavaScript popped up in a Computer Science class I'm taking. They rec using a recursive approach. I'm wondering what your thoughts are on solving this problem using recursion. And, what approach would you take if you were only given 1 array to start instead of two. I guess just split it into two using slice() ? Thanks a ton!

aaroncurtisyoga