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 users = [ | |
{ name: 'Alan', surname: 'Shearer' }, | |
{ name: 'Micheal', surname: 'Owen' }, | |
{ name: 'Peter', surname: 'Beardsley' } | |
]; | |
var user; | |
/* | |
for (var i = 0; i < users.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
const numbers = [ 10, 20, 30, 40, 50, 60 ]; | |
function reject(numbers, iteratorFunction) { | |
return numbers.filter(function(number){ | |
return (number < 15); | |
}); | |
} |
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
const users = [ | |
{ id: 1, admin: true }, | |
{ id: 2, admin: false }, | |
{ id: 3, admin: false }, | |
{ id: 4, admin: false }, | |
{ id: 5, admin: true }, | |
]; | |
let filteredUsers = users.filter(function(user) { | |
return user.admin === 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
const numbers = [15, 25, 35, 45, 55, 65, 75, 85, 95]; | |
let filteredNumbers = numbers.filter(function(number) { | |
return number > 50; | |
}); | |
console.log(filteredNumbers); |
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
const post = { id: 10, title: 'New Post' }; | |
const comments = [ | |
{ postId: 4, content: 'Great reading' }, | |
{ postId: 3, content: 'Good article' }, | |
{ postId: 10, content: 'Very good reading' } | |
]; | |
function commentsForPost(post, comments) { | |
return comments.filter(function(comment) { |
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
const products = [ | |
{ name: 'cucumber', type: 'vegetable' }, | |
{ name: 'banana', type: 'fruit' }, | |
{ name: 'celery', type: 'vegatable' }, | |
{ name: 'orange', type: 'fruit' }, | |
]; | |
let filteredProducts = []; | |
/* |
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
const cars = [ | |
{ model: 'Ferrari', price: 'R2 500 000' }, | |
{ model: 'Porsche 911', price: 'R1 500 000' }, | |
]; | |
// plucking a value | |
let prices = cars.map(function(car) { | |
return car.price; | |
}); |
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 numbers = [1,2,3,4,5,6]; | |
var doubledNumbers = []; | |
for (var i = 0; i < numbers.length; i++) { | |
doubledNumbers.push(numbers[i] * 2); | |
} | |
var doubled = numbers.map(function(number){ | |
return number * 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
var images = [ | |
{ height: 10, width: 30 }, | |
{ height: 20, width: 90 }, | |
{ height: 54, width: 32 } | |
]; | |
var areas = []; | |
images.forEach(function(image) { | |
var calculatedArea = image.height * image.width; |
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
// create an array of numbers | |
var numbers = [1,2,3,4,5]; | |
// create a varaible to hold the sum | |
var sum = 0; | |
function adder(number) { | |
sum += number; | |
} |