Chain Without Mutating
Chain Without Mutating
Chaining can express a data pipeline clearly: keep the records that matter, order them, trim the list, then transform the shape. The risk is that some array methods mutate.
sort changes the array it is called on, so a safe pipeline sorts a copy when the original order still matters elsewhere. That preservation is important in UI state and cached data.
Your task: Complete topPublishedTitles so it returns the titles of the two published courses with the most enrollments. Keep the original course array in its original order.
Free with a JS Exercises account
Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.
By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.
Chain Without Mutating
Chaining can express a data pipeline clearly: keep the records that matter, order them, trim the list, then transform the shape. The risk is that some array methods mutate.
sort changes the array it is called on, so a safe pipeline sorts a copy when the original order still matters elsewhere. That preservation is important in UI state and cached data.
Your task: Complete topPublishedTitles so it returns the titles of the two published courses with the most enrollments. Keep the original course array in its original order.