Ad space (banner)
๐ŸŸฃJulia Lessons
Lesson 23 / 68

Transforming an array with map

This lesson covers transforming an array with Julia's map, with the aim of processing every element in one go.

map(function, array) performs the same work on each element and builds a new array. Picture a machine on a conveyor belt that processes every product it passes in the same way.

The sample code builds doubled by doubling each element of the original array [1, 2, 3] with map(n -> n * 2, nums). The n -> n * 2 form is a lambda (an anonymous function) defined on the spot.

A common early stumble is that map() returns a new array rather than changing the original. Compared with writing a for loop, it makes what you want to do plain in the code.

In professional work, this shape comes up whenever data is transformed in bulk — applying tax to prices, converting units.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Julia directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)