Join Leigh Lawhon for an in-depth discussion in this video Bubble sort, part of Web Portfolio Projects: Sortable Table and Arrays.
- [Instructor] Let's start with a flag for swapped…and we don't have to assign that right now…and then we'll perform a do while loop.…Inside our do while,…let's say swapped is equal to false…and then we want to loop through our array.…So we'll do a for…and we'll say let i equal zero.…And while i is less than the arr.length,…we'll perform our function as well as iterate our i…so i plus plus.…
Inside our for loop, we'll create a const for j i plus one…and now we can check whether or not the current row exists…as well as the following row.…So I'll say if arr i and arr j exist,…then we can check our values…like we did in the regular sort.…
So I'm just going to copy that information…and I'm going to change a and b to arr i and arr j.…Now that we have our values,…let's check to see if x is greater than y.…And if so, we want to swap them so let's create a var temp…and that's going to be equal to arr i.…
Then to swap them, we simply assign arr i now to arr j.…Then we'll take our arr j…and give it the stored value of temp.…
- 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.