Skip to content

WEBEU2 - JavaScript-II - Isaac Aderogba 🇮🇪 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

IsaacAderogba
Copy link
Owner

No description provided.

Copy link
Collaborator

@maximesalomon maximesalomon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job on this Isaac 👍 Seems like you have a pretty good understanding of array methods, callbacks, and closures!

You had one exercise were you misread the question. Try to fix that when you have some time.

let fullName = [];
const fullName = [];

runners.forEach(element => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to use a more descriptive name than element when using array methods --> runner could be a good name here

console.log(fullName);

// ==== Challenge 2: Use .map() ====
// The event director needs to have all the runner's first names converted to uppercase because the director BECAME DRUNK WITH POWER. Convert each first name into all caps and log the result
let allCaps = [];
// Explicit approach
const allCaps = runners.map(function(element) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use ES6 arrow function?

let largeShirts = [];
const largeShirts = runners.filter(function(element) {
return element.shirt_size === "L"
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ES6 array function are cleaner, start to use them:
--> const largeShirts = runners.filter(runner => runner.shirt_size === "L");

}

last(items, function(lastItem) {
console.log("Q2 Callbacks: " + lastItem);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the question again

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It says "last passes the last item of the array into the callback".

The code below passes the last item of the array into the callback:

return cb(**arr.length - 1**);

Where have I misunderstood that?

contains("Peanuts", items, function(booleanValue) {
console.log("Q5.2 Callbacks: " + booleanValue);
});

/* STRETCH PROBLEM */

function removeDuplicates(array, cb) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job doing the stretch!

@@ -1,21 +1,55 @@
// ==== Challenge 1: Write your own closure ====
// Write a simple closure of your own creation. Keep it simple!

function whoLikesIceCream(yourName) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍦


/* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */


// ==== Challenge 2: Create a counter function ====
const counter = () => {
// Return a function that when invoked increments and returns a counter variable.
let count = 0;
return function() {
return ++count;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between ++count and count++?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants