Check out a free preview of the full A Practical Guide to Algorithms with JavaScript course

The "Unique Sort Exercise" Lesson is part of the full, A Practical Guide to Algorithms with JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

In this exercise, students Implement unique sort, which removes duplicates from an array.


Transcript from the "Unique Sort Exercise" Lesson

>> Bianca: So now it's your turn. Your goal here
>> Bianca: Is to transform this simple sorting algorithm into a uniqSort. So a uniqSort takes an array with duplicates, removes the duplicates, and returns the sorted array.
>> Bianca: And so, the sort is happening for you on line ten. You don't need to worry too much about that.

>> Bianca: This method here, or this function here, means that it's gonna be returned in ascending order. If you want it to be in descending order, you just swap these. And the reason we have to do this is because the Java script made of sorts, it's like a string sort.

So if you have 1, 2, 3, and 12, it'll do 1, 12, 2, 3. And so, that's why we need to pass this callback to tell the sort that we want to actually operate on this kind of comparison, which is a greater than or less than comparison.
>> Bianca: Okay, so you should be able to edit this directly in the slide.

You can also open it in And then, you can fork it. And then, you can save them if you want. And you can have a copy of all the exercises that you've worked on and your solutions in your own You will have to make a account though.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now