Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on May 14, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions 22 assets/array-methods-exercises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const flowers = [
{ name: 'tulip', color: 'red' },
{ name: 'dandelion', color: 'yellow' },
{ name: 'rose', color: 'red' },
{ name: 'daisy', color: 'white' },
{ name: 'lily', color: 'white' },
];

// Exercise 1
// use `map` to make the first letter of al flowers a capital.
// so 'tulip' becomes 'Tulip' etc.

// Exercise 2
// use `filter` to get only the flowers with a name of 4 characters

// Exercise 3
// use `reduce` to create an object that contains
// the total number of flowers for each color

// Exercise 4 (bonus)
// use `some` or `every` in combination with another array method
// to find out if all flowers with five letters are red
80 changes: 80 additions & 0 deletions 80 assets/sync-async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const greenGrocer = {
buyApples: function(quantity) {
return quantity + ' apples';
},
buyTomatoes: function(quantity) {
return quantity + ' tomatoes';
},
buyCauliflower: function(quantity) {
return quantity + ' cauliflower';
},
};

const cheeseShop = {
buyCheese: function(type, weight) {
this.cutCheese(type, weight);

return weight + 'gr ' + type + ' cheese';
},

cutCheese: function(type, weight) {
const stopTime = Date.now() + 100;
while (Date.now() < stopTime);
},
};

const bakery = {
buyBread: function(breadReadyCallback, type, quantity) {
setTimeout(function() {
breadReadyCallback(quantity + ' ' + type);
}, 1000);
},
};

function visitGreengrocer() {
console.log('=== Greengrocer ===');

const beforeBuy = Date.now();

const fruitsAndVegetables = [
greenGrocer.buyApples(2),
greenGrocer.buyTomatoes(2),
greenGrocer.buyCauliflower(1),
];

const timeTaken = (Date.now() - beforeBuy).toFixed(2);

console.log('You bought: ', fruitsAndVegetables);
console.log('This took: ' + timeTaken + 'ms\n');
}

function visitCheeseShop() {
console.log('=== Cheese Shop ===');
const beforeBuy = Date.now();

const cheese = cheeseShop.buyCheese('belegen', 500);

const timeTaken = (Date.now() - beforeBuy).toFixed(2);

console.log('You bought: ' + cheese + '');
console.log('This took: ' + timeTaken + 'ms\n');
}

function visitBakery() {
console.log('=== Bakery ===');
const beforeBuy = Date.now();

const breadReady = function(bread) {
const timeTaken = (Date.now() - beforeBuy).toFixed(2);
console.log('--- Callback from Bakery ---');
console.log('You bought: ' + bread + '');
console.log('This took: ' + timeTaken + 'ms\n');
};

bakery.buyBread(breadReady, 'fijn volkoren', 1);
console.log(`We'll call you back!\n`);
}

visitGreengrocer(); // ?.
visitBakery(); // ?.
visitCheeseShop(); // ?.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.