LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code
JS
// on document ready
$(function(){
  var animals = [
    {
      id: 1,
      name: "Tails",
      type: "Tiger",
      adoptible: false
    },{
      id: 3,
      name: "Soul",
      type: "Cat",
      adoptible: true
    },{
      id: 10,
      name: "Fred",
      type: "Dog",
      adoptible: true
    },{
      id: 18,
      name: "Fluffy",
      type: "Elephant",
      adoptible: false
    }
  ];
  
  var sortedAnimals = _.sortBy(animals, 'type');
  // sortedAnimals = sortedAnimals.reverse();
  $('.results').html("The first adoptible animal's name is " + sortedAnimals[0].name);

  // TASK #2 
  // find the id of the next animal to be added to our list
  var newAnimal = {
    name: "Tialya",
    type: "Shark",
    adoptible: false
  }
  var itemIds = _.pluck(animals, 'id'); // [1, 3, 10, 18]
  newAnimal.id = _.max(itemIds) + 1;
  animals.push(newAnimal);
  
});





Term
Fri, 01/12/2018 - 16:46

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv