From the course: Learning Functional Programming with JavaScript ES6+
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Sorting - JavaScript Tutorial
From the course: Learning Functional Programming with JavaScript ES6+
Sorting
- [Instructor] Now that we've seen how to use Slice to prevent mutation, let's take a look at the function Sort. As you may have guessed by the name, this function is used when you want to change the order of elements in an array. This would be very useful, for example, if we had an array of names and wanted to sort it in alphabetical order. Or if we had an array of employees and wanted to sort them by the number of years they've been with the company, for example. Before we look at how to use sort, it's very important to remember that Sort is a mutating function. Which means that it actually modifies the original version of the array that it's called on. In a previous video we saw how JavaScript's built-in Slice function could be used to make a copy of an array, which would then allow us to use mutating functions such as Sort without modifying the original array. And that's exactly what we're going to do with Sort. So, whenever we use Sort instead of simply calling it using…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
JavaScript: Functional parts1m 53s
-
(Locked)
The spread operator5m 30s
-
Mapping5m 11s
-
(Locked)
Filtering6m 59s
-
(Locked)
Every/some5m 46s
-
(Locked)
Slicing3m 38s
-
(Locked)
Sorting5m 11s
-
(Locked)
Reducing6m 23s
-
(Locked)
Combining functions6m 40s
-
(Locked)
Challenge: Recreate the map function1m 3s
-
(Locked)
Solution: Recreate the map function3m 6s
-
(Locked)
-
-
-