# Transforming Data

Hand a function to another function and let it do the looping. With map, filter, reduce and sort you can turn a raw list into a leaderboard in a few readable lines.

Updated: November 14, 2026

## [Functions as Values](https://www.ask-codey.com/courses/javascript-in-depth/topics/javascript-callbacks)

1. [Functions as Values: Callbacks](https://www.ask-codey.com/lessons/javascript-callbacks-functions-as-values) (Apprentice): In JavaScript a function is a value you can hand to another function, which calls it for you; that handed-over function is a callback, and it's how sorting, timers and buttons work.

## [Array Methods in JavaScript](https://www.ask-codey.com/courses/javascript-in-depth/topics/javascript-array-methods)

1. [map and filter](https://www.ask-codey.com/lessons/javascript-array-methods-map-and-filter) (Apprentice): map turns every item of an array into something new, filter keeps only the items that pass a test, and chained together they turn raw data into exactly the list a screen needs.
2. [reduce](https://www.ask-codey.com/lessons/javascript-array-methods-reduce) (Journeyman): reduce walks through an array carrying a running total, so a whole list of scores, prices or plays boils down to one answer, such as a total, a count or a best score.
3. [Sorting Arrays](https://www.ask-codey.com/lessons/javascript-array-methods-sort) (Apprentice): sort puts an array in order, but it compares items as text unless you give it a compare function, and it changes the array itself, so toSorted is the way to get a sorted copy and keep the original.

## [Exercise: High-Score Leaderboard](https://www.ask-codey.com/courses/javascript-in-depth/topics/exercise-javascript-high-score-leaderboard)

1. [Exercise: High-Score Leaderboard](https://www.ask-codey.com/lessons/exercise-javascript-high-score-leaderboard) (Journeyman): Finish six functions that turn an arcade game's high-score list into its top 3, display lines, totals and a numbered leaderboard, using map, filter, reduce and sort, and let the tests check each one.

Source: https://www.ask-codey.com/courses/javascript-in-depth/chapters/transforming-data-in-javascript
