Last active
August 29, 2015 14:15
-
-
Save AllThingsSmitty/06523ace403e6b05bed0 to your computer and use it in GitHub Desktop.
Simplifying JS functions with Lo-Dash
This file contains hidden or 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
// Get a simple array of objects | |
var drinks = [ | |
{ 'name': 'Coke', 'quantity': 2 }, | |
{ 'name': 'Red Bull', 'quantity': 6 } | |
]; | |
// Get all the drink names using the _.pluck() function | |
var currentDrinks = _.pluck(drinks, 'name'); | |
console.log(currentDrinks); | |
// → ['Coke', 'Red Bull'] | |
// Get the drink with the highest stock level using the _.max() function | |
var drinks, | |
currentDrinks, | |
maxQuantity; | |
drinks = [ | |
{ 'name': 'Coke', 'quantity': 2 }, | |
{ 'name': 'Red Bull', 'quantity': 6 } | |
]; | |
currentDrinks = _.pluck(drinks, 'name'); | |
console.log(currentDrinks); | |
maxQuantity = _.max(drinks, 'quantity'); | |
console.log(maxQuantity); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment