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) |
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' } ]
You're missing a comma after the Harold object. :)
Thanks for your videos I'm really enjoying your series on functional programming.
Also, the name
prop in the for
is backwards animals.name[i]
should be animals[i].name
.
Thanks for pointing that out! Fixed!
@mpj , Thanks for the simple and great tutorial 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
0-array.js should have a comma on line 5