Skip to content

Instantly share code, notes, and snippets.

@mpj
Last active May 25, 2023 15:48
Show Gist options
  • Select an option

  • Save mpj/c5ae804e576042b3287d to your computer and use it in GitHub Desktop.

Select an option

Save mpj/c5ae804e576042b3287d to your computer and use it in GitHub Desktop.

Revisions

  1. mpj revised this gist Aug 23, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 1-forloop.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    var names = []
    for (var i = 0; i < animals.length; i++) {
    names.push(animals.name[i])
    names.push(animals[i].name)
    }
  2. mpj revised this gist Aug 23, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 0-array.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ var animals = [
    { name: 'Fluffykins', species: 'rabbit' },
    { name: 'Caro', species: 'dog' },
    { name: 'Hamilton', species: 'dog' },
    { name: 'Harold', species: 'fish' }
    { name: 'Harold', species: 'fish' },
    { name: 'Ursula', species: 'cat' },
    { name: 'Jimmy', species: 'fish' }
    ]
  3. mpj revised this gist Jun 28, 2015. 4 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
  4. mpj revised this gist Jun 28, 2015. 6 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
  5. mpj revised this gist Jun 28, 2015. 4 changed files with 4 additions and 1 deletion.
    1 change: 1 addition & 0 deletions map-advanced.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    var names = animals.map(function(animal) { animal.name + ' the ' + animal.species })
    1 change: 1 addition & 0 deletions map-basic-arrow-x.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    var names = animals.map((x) => x.name)
    1 change: 1 addition & 0 deletions map-basic-arrow.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    var names = animals.map((animal) => animal.name)
    2 changes: 1 addition & 1 deletion map-basic.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    var names = animals.map(function(x) { return x.name })
    var names = animals.map(function(animal) { return animal.name })
  6. mpj revised this gist Jun 28, 2015. 3 changed files with 6 additions and 2 deletions.
    3 changes: 1 addition & 2 deletions array.js
    Original file line number Diff line number Diff line change
    @@ -5,5 +5,4 @@ var animals = [
    { name: 'Harold', species: 'fish' }
    { name: 'Ursula', species: 'cat' },
    { name: 'Jimmy', species: 'fish' }
    ]

    ]
    4 changes: 4 additions & 0 deletions forloop.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    var names = []
    for (var i = 0; i < animals.length; i++) {
    names.push(animals.name[i])
    }
    1 change: 1 addition & 0 deletions map-basic.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    var names = animals.map(function(x) { return x.name })
  7. mpj revised this gist Jun 28, 2015. 1 changed file with 1 addition and 14 deletions.
    15 changes: 1 addition & 14 deletions array.js
    Original file line number Diff line number Diff line change
    @@ -6,17 +6,4 @@ var animals = [
    { name: 'Ursula', species: 'cat' },
    { name: 'Jimmy', species: 'fish' }
    ]

    var names = []
    for (var i = 0; i < animals.length; i++) {
    names.push(animals.name[i])
    }
    var names = animals.map(function(x) { return x.name })

    var names = animals.map((x) => x.name + ' the ' + x.species)
    var names = animals.map((x) => { return x.name })
    var names = animals.map((x) => x.name)





  8. mpj renamed this gist Jun 28, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. mpj renamed this gist Jun 28, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. mpj revised this gist Jun 28, 2015. 1 changed file with 2 additions and 9 deletions.
    11 changes: 2 additions & 9 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -11,18 +11,11 @@ var names = []
    for (var i = 0; i < animals.length; i++) {
    names.push(animals.name[i])
    }

    var names = [] ;for (var i = 0; i < animals.length; i++) { names.push(animals.name[i]) }

    var names = animals.map(function(x) { return x.name })

    var names = animals.map((x) => x.name + ' the ' + x.species)
    var names = animals.map((x) => { return x.name })
    var names = animals.map((x) => x.name)
    var names = animals.map((x) => x.name + ' the ' + x.species)

    var numAnimals = animals.reduce((prev, cur) => {
    if(!prev[cur.species]) prev[cur.species] = 0;
    prev[cur.species]++
    , {})



  11. mpj revised this gist Jun 26, 2015. 1 changed file with 11 additions and 3 deletions.
    14 changes: 11 additions & 3 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -12,9 +12,17 @@ for (var i = 0; i < animals.length; i++) {
    names.push(animals.name[i])
    }

    names = animals.map(function(x) { return x.name })
    names = animals.map((x) => { return x.name })
    names = animals.map((x) => x.name)
    var names = [] ;for (var i = 0; i < animals.length; i++) { names.push(animals.name[i]) }

    var names = animals.map(function(x) { return x.name })
    var names = animals.map((x) => { return x.name })
    var names = animals.map((x) => x.name)
    var names = animals.map((x) => x.name + ' the ' + x.species)

    var numAnimals = animals.reduce((prev, cur) => {
    if(!prev[cur.species]) prev[cur.species] = 0;
    prev[cur.species]++
    , {})



  12. mpj created this gist Jun 26, 2015.
    21 changes: 21 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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' }
    ]

    var names = []
    for (var i = 0; i < animals.length; i++) {
    names.push(animals.name[i])
    }

    names = animals.map(function(x) { return x.name })
    names = animals.map((x) => { return x.name })
    names = animals.map((x) => x.name)