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
let animals = [ | |
{name: 'Tibbers', type: 'cat', isNeutered: true, age: 2}, | |
{name: 'Fluffball', type: 'rabbit', isNeutered: false, age: 1}, | |
{name: 'Strawhat', type: 'cat', isNeutered: true, age: 5} | |
] | |
let allNeutered = animals.every(animal => {return animal.isNeutered}); | |
//will return false because not all values under isNeutered evaluates to true |
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
let animals = [ | |
{name: 'Tibbers', type: 'cat', isNeutered: true, age: 2}, | |
{name: 'Fluffball', type: 'rabbit', isNeutered: false, age: 1}, | |
{name: 'Strawhat', type: 'cat', isNeutered: true, age: 5} | |
] | |
/*using functional filter() where a represents an item in the array*/ | |
let neuteredAnimals = animals.filter((a) => { | |
return a.isNeutered; | |
}); |
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
let animals = [ | |
{name: 'Tibbers', type: 'cat', isNeutered: true, age: 2}, | |
{name: 'Fluffball', type: 'rabbit', isNeutered: false, age: 1}, | |
{name: 'Strawhat', type: 'cat', isNeutered: true, age: 5} | |
] | |
/*using imperative*/ | |
let neuteredAnimals = []; | |
for (let i=0; i < animals.length; i++){ |
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
let animals = [ | |
{name: 'Tibbers', type: 'cat', isNeutered: true, age: 2}, | |
{name: 'Fluffball', type: 'rabbit', isNeutered: false, age: 1}, | |
{name: 'Strawhat', type: 'cat', isNeutered: true, age: 5} | |
] | |
animalTypeFound = animals.find( animal => animal.type === 'cat' ); | |
// animalTypeFound will return: | |
// {name: 'Tibbers', type: 'cat', isNeutered: true, age: 2} |
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
let animals = [ | |
{name: 'Tibbers', type: 'cat', isNeutered: true, age: 2}, | |
{name: 'Fluffball', type: 'rabbit', isNeutered: false, age: 1}, | |
{name: 'Strawhat', type: 'cat', isNeutered: true, age: 5} | |
] | |
// what you need: | |
// ['Tibbers', 'Fluffball', 'Strawhat'] | |
let animalNames = animals.map(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
let numbers = [100, 20, 10]; | |
// result will return 70 as the value | |
// The function inside reduce will run twice. | |
// the first time, x = 100, y = 20 | |
// the second time, x = 80, y = 10 | |
result = numbers.reduce((x, y) => { return x - y; }); | |
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
let animals = [ | |
{name: 'Tibbers', type: 'cat', isNeutered: true, age: 2}, | |
{name: 'Fluffball', type: 'rabbit', isNeutered: false, age: 1}, | |
{name: 'Strawhat', type: 'cat', isNeutered: true, age: 5} | |
] | |
// How old are all the animals combined? | |
// 0 is the starting value and acts as the first acculmulator value | |
// will return 8 |
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
let animals = [ | |
{name: 'Tibbers', type: 'cat', isNeutered: true, age: 2}, | |
{name: 'Fluffball', type: 'rabbit', isNeutered: false, age: 1}, | |
{name: 'Strawhat', type: 'cat', isNeutered: true, age: 5} | |
] | |
let someAreCats = animals.some(animal => {return animal.type === 'cat'}); | |
// will return true because at least one animal.type returned 'cat' |
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
let animals = [ | |
{name: 'Tibbers', type: 'cat', isNeutered: true, age: 2, enteredPagent: true, cutenessScore: 347}, | |
{name: 'Fluffball', type: 'rabbit', isNeutered: false, age: 1, enteredPagent: true, cutenessScore: 193}, | |
{name: 'Strawhat', type: 'cat', isNeutered: true, age: 5, enteredPagent: false, cutenessScore: 521} | |
] | |
//lets say you want to find the total cuteness score of all valid pagent entrants | |
let totalScore = animals | |
.filter(animal => {return animal.isNeutered}) |
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
<div class="feedSection col l12 s12" *ngFor="let item of feed"> | |
<h3>{{item.details.publication}}</h3> | |
<div class="featured col l6 s12"> | |
<p class="date">{{item.items[0].pubDate | date:'dd MMM'}}</p> | |
<a href="{{item.items[0].link}}">{{item.items[0].title}}</a> | |
</div> | |
<div class="col l6 s12"> | |
<ul> | |
<li *ngFor="let single of item.items |slice: 1:10"> | |
<a href="{{single.link}}">{{single.title}}</a> |
OlderNewer