Giter VIP home page Giter VIP logo

hyf-javascript2's People

Contributors

zydan1 avatar

Watchers

 avatar

Forkers

elmira202003

hyf-javascript2's Issues

Feedback homework JS2 Week 3

Hi Hamza, here is my feedback on your homework.

Step 4.1

You were supposed to call the foo function like this (notice no parentheses after bar):

foo(bar);

When calling foo in this way you pass the function bar as a parameter to foo. In your case, you are calling bar and pass the result the result of bar (which is undefined) to foo. We explained this in the last lecture.

The correct code is like this:

function foo(callback) {
    callback();
}
function bar() {
    console.log('Hello, I am bar!');
}
foo(bar);

Step 4.2

While the code works, the approach you have taken for testing divisibility is a bit convoluted:

  • First you divide the number by respectively 3 or 5.
  • Then you test using the module operator whether the division result is a whole number.

It is simpler and easier to follow if you use the modulo operator directly, e.g.

if (arrNum[j] % 3 === 0) {
    sayThree(arrNum[j]);
}
if (arrNum[j] % 5 === 0) {
    sayFive(arrNum[j]);
}

Step 4.3

Missing

Step 4.4

Missing

Step 4.5

Missing

Step 4.6

See the solution that I posted in slack shows how you can do this with a recursive function.

Step 4.7

I'm not entirely sure, but I think you understand the difference between call by value and call by reference.

Step 5

OK, but you can replace += by simply + because the value of x is not used after the return statement.

Bonus

Both solutions produce the correct result.

In the second solution you don't really need the value variable. And you should not use console.log inside your function. Let the caller decide what to do with the new array, perhaps console.log it or do something else. It's all about reusability. Look how I modified your code:

function newArray2(arr) {
    let obj = {};
    let newArray = [];
    // let value = 1
    for (let i = 0; i < arr.length; i++) {
        obj[arr[i]] = 1;
        // value++;
    }
    for (let key in obj) {
        newArray.push(key);
    }
    return newArray;
}

console.log(newArray2(arr));

hey there

hey Hamza your code is nice but I have a comment on it :

line -68- your using of that map in that situation is useless because you are just taking what from the -filter an adding it to a new array using -map without modifying anything, my advice use the -map before -filtering in this case.
semicolon line 71 & 80

great job man
regards.

Homework for week3

Hey boss, first you should introduce some line separators within the code to make it easier for the reviewer to see which code is for which.

Have you tried running the code? It does not give the expected results. J. 6/II/18

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.