Last active
May 25, 2023 15:48
-
-
Save mpj/c5ae804e576042b3287d to your computer and use it in GitHub Desktop.
Code to the video - "Map: Part 2 of Functional Programming in JavaScript"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var animals = [ | |
{ name: 'Fluffykins', species: 'rabbit' }, | |
{ name: 'Caro', species: 'dog' }, | |
{ name: 'Hamilton', species: 'dog' }, | |
{ name: 'Harold', species: 'fish' }, | |
{ name: 'Ursula', species: 'cat' }, | |
{ name: 'Jimmy', species: 'fish' } | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var names = [] | |
for (var i = 0; i < animals.length; i++) { | |
names.push(animals[i].name) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var names = animals.map(function(animal) { return animal.name }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var names = animals.map(function(animal) { animal.name + ' the ' + animal.species }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var names = animals.map((animal) => animal.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var names = animals.map((x) => x.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, the
name
prop in thefor
is backwardsanimals.name[i]
should beanimals[i].name
.