Skip to content

James Phillips - #149

Open
CASDFJ wants to merge 10 commits into
bloominstituteoftechnology:masterfrom
CASDFJ:master
Open

James Phillips#149
CASDFJ wants to merge 10 commits into
bloominstituteoftechnology:masterfrom
CASDFJ:master

Conversation

@CASDFJ

@CASDFJ CASDFJ commented Jun 26, 2018

Copy link
Copy Markdown

Callbacks done

CASDFJ added 9 commits June 26, 2018 16:06
Callbacks done
function conversion
finished function conversion
modified array challenge
Array 1-4 challenges done
did arrays need to do closures
did closure js
modified function conversions
modified array methods

@EricHech EricHech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good stuff man! Keep up the good work. I hope my comments are helpful.

Also, awesome commit frequency!

// ==== Challenge 1: Use .forEach() ====
// The event director needs both the first and last names of each runner for their running bibs. Combine both the first and last names into a new array called fullName.
let fullName = [];
runners.forEach(function(element){fullName.push(element.first_name + ' ' + element.last_name)});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The second version is styled more preferably, though with arrow syntax you could stick this all on one line. Also, this is a good use-case for string interpolation and template literals (backticks and dollar-sign curly braces).


//or//

let allCaps = runners.map((person) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice, this second one here looks really good.


// Problem 2
let ids = [];
ids = runners.filter(function(element){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think this .filter() is doing what you think it should. This is looking at every element in the array and checking to see if it has an id property, and if it does, then it will return that element. Therefore, since all elements in your array have ids, this filter doesn't change anything. Maybe if you did return element.donation > 100, then you could get an array of all the runners who donated more than $100. This is actually a practical use-case; maybe you want to put those runners in a unique category to recieve a special "thank you" email, for example.

Comment thread assignments/callbacks.js
function sumNums(x, y, cb) {
// sumNums adds two numbers (x, y) and passes the result to the callback.
let sum = x + y;
cb(sum);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is good. You could also have done:
cb(x + y)

Comment thread assignments/callbacks.js
function contains(item, list, cb) {
// contains checks if an item is present inside of the given array/list.
// Pass true to the callback if it is, otherwise pass false.
if(list.includes(item) === true) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This works too:
if(list.includes(item) === true) cb(true);
else cb(false);

When one-lined, you don't need brackets, and the else will pair with the if directly above it. I would only do this for very short statements like you have here, though, and some linters don't like you to do it in the way that I'm showing you anyway because it makes it harder to edit the code by adding in more lines. Does that make sense?

Comment thread assignments/closure.js
console.log(example);

// ==== Challenge 2: Create a counter function ====
const counter = () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Did you grab this from the solution or from a fellow student, or did you write it yourself? Either is fine, it's just good for me to know.

Comment thread assignments/closure.js
const counterFactory = () => {
let count = 0;
return {
increment: () => (++count),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is fine:
increment: () => ++count,

let anotherFunction = param => `${param}`;

//correct way//////////////////////////
let anotherFunction = (param) => param;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good, so there is no need for the string interpolators here, and it seems like you realized that and removed them in the last example.

just adjusting base of your commemts Eric

thanks for the feedback. Always appreciate it
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