Skip to content
This repository was archived by the owner on Aug 31, 2019. It is now read-only.

advanced javascript hw - #17

Closed
Calv519 wants to merge 6 commits into
bloominstituteoftechnology:masterfrom
Calv519:master
Closed

advanced javascript hw #17
Calv519 wants to merge 6 commits into
bloominstituteoftechnology:masterfrom
Calv519:master

Conversation

@Calv519

@Calv519 Calv519 commented Jul 18, 2017

Copy link
Copy Markdown

No description provided.

Comment thread src/arrays.js
}
let total = memo; // 10
for (; i < elements.length; i++) {
total += elements[i];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You wouldn't want to use += here. That is doing addition or string concatenation. You would want to actually overwrite the memo. memo = cb(memo, elements[i]);

Comment thread src/arrays.js
// If `cb` returns `true` then return that element.
// Return `undefined` if no elements pass the truth test.
for (let i = 0; i < elements.length; i++) {
if (cb(elements[i])) { // tai says look at this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This works fine. Because cb is returning true or false it will pass or fail the if statement

Comment thread src/class.js
// for a potential password that will be compared to the `password` property.
// Return true if the potential password matches the `password` property. Otherwise return false.

class User {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This may have had something to do with the file but the indentation is different here than it was in the previous file. I recommend a tab of 2 spaces. The main point though is to pick one style and stay consistent with it throughout your project.

Comment thread src/class.js
this.age = options.age;
}
growOlder() {
return this.age++;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Something funny to be aware of here is that the ++ postfix operator will apply the incrementation AFTER the value has been returned. So if you have 1 and you go return 1++; a 1 is returned and then it is turned into a 2.

Comment thread src/closure.js

const counter = () => {
let count = 0;
return () => ++count;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So here you're using ++ as a prefix operator which increments the value BEFORE returning it. Kind of a funny difference that trips people up from time to time.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good job using the shorthand syntax

Comment thread src/closure.js
return {
increment: () => (++count),
decrement: () => (--count)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You're missing a ; here

Comment thread src/es6.js
const food = 'pineapple';

var isMyFavoriteFood = function(food) {
const isMyFavoriteFood = (food) =>{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Put a space after the =>

Comment thread src/es6.js
}
class User {
constructor(options) {
this.username = options.username

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Make sure everything inside of the constructor method is indented

Comment thread src/es6.js
}
sayHi () {
return `${username} says hello!`;
};

@SunJieMing SunJieMing Jul 20, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A class also does not need a ; at the end. You are also missing a closing } after the sayHi method

Comment thread src/es6.js

var argsToCb = function (cb) {
var args = Array.prototype.slice.call(arguments);
const argsToCb = (cb) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You're missing an =>

Comment thread src/objects.js
const values = (obj) => {
return Object.keys(obj).map((key) => {
return obj;
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You're missing a ; here

Comment thread src/recursion.js
// Complete the following functions.

const nFibonacci = (n) => {
if (n <= 1) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same thing with indendation

Comment thread src/recursion.js

const nFibonacci = (n) => {
if (n <= 1) {
return 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Need a ; here

Comment thread src/recursion.js
if (n <= 1) {
return 1
}
return n * nFibonacci(n-1);

@SunJieMing SunJieMing Jul 20, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Put space around your - so: n - 1

Comment thread src/recursion.js
};

const nFactorial = (n) => {
if (n <= 1) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With the factorial you would need to return 1 as the base case.

if (n <= 1) return 1;
return n * nFactorial(n - 1);

Comment thread src/recursion.js
};

const checkMatchingLeaves = (obj) => {
if (obj.property) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know you don't have a finished solution here but it's always good to mind the indentation, even with incomplete code.

Comment thread src/this.js
// set a username and password property on the user object that is created
}
checkPassword(passwordToCompare) {
if (this.password === passwordToCompare) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can be simplified to return this.password === passwordToCompare;
The === means that the expression will be evaluated into true or false before it is returned

@SunJieMing SunJieMing closed this Jul 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants