Join Leigh Lawhon for an in-depth discussion in this video Intro to merge sort, part of Web Portfolio Projects: Sortable Table and Arrays.
- [Instructor] Merge Sort works…by dividing the array into pairs,…sorting those pairs, and then merging the results…as you see in the video.…To get a merge sort, we'll be using two functions,…the mergeSort, which splits the arrays,…and the merge, which sorts them.…Let's start with the mergeSort.…The first thing we want to do is we want to check…to see if the array length…is less than or equal to 1.…
And if it is, let's just return the array.…There's no point in sorting it.…Then we're going to create a const…for a middl,…left and right.…And the middl is going to be equal…to the array length divided by 2.…And in case that array length is an odd number,…let's go ahead and wrap that in a Math.floor.…And that'll round down for us.…
The left, on the other hand, is going to be equal…to array.slice,…and we'll start at the 0 index.…And we'll go through the middle index…that we just created.…The right is equal to array.slice…and we're going to pass in just the middle.…That'll automatically go to the end of the array.…Finally, we're going to return the merge function,…
- Sorting your table efficiently
- Filtering null values and sorting nodes
- Sorting algorithms, including merge sort and insertion sort
- Performance testing
- Creating your own algorithm
- Design components
- Adding icons
Skill Level Intermediate
Workflow Tools for Web Developerswith Christina Truong1h 13m Intermediate
What you should know1m 33s
1. Getting Started
2. Sorting Our Table Efficiently
3. Sorting Algorithms
4. Creating Our Own Algorithm
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.