GithubHelp home page GithubHelp logo

hyf-javascript2's People

Contributors

elmira202003 avatar

Watchers

 avatar

hyf-javascript2's Issues

Feedback homework JS2 Week 3

Hi Elmira, here is my feedback on your homework. Overall, well done!

Step 4.1

OK

Step 4.2

I noticed you copied my solution. No point in me reviewing my own code. Therefore, I took your code from an earlier commit:

let sayNumber = [];

function sayThree() {
    sayNumber.push('sayThree');
}

function sayFive() {
    sayNumber.push('sayFive');
}

function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) {

    let numberArr = [];
    for (let i = startIndex; i <= stopIndex ; i++){
        numberArr.push(i);
        if (i % 3 === 0) {
            sayThree();
        }
        if (i % 5 === 0) {
            sayFive();
        }
    }
    console.log('Thee original array is : ' + numberArr);
    console.log(sayNumber);
   
}

threeFive(10, 15, sayThree, sayFive);

I would have been happy with your original, own solution: it was close enough.

Step 4.3

As we explained in the last lecture, it is better to design your functions for reusability. In this case, it would be better if your repeatStringNumTimes would simply return the new string without console logging it. Then you can console.log it when you call your function, like so:

function repeatStringNumTimes(str, num) {

    str = num < 0 ? "" : str;
    let newString = "";
    for (let i = 0; i < num; i++) {
        newString += str;
    }
    return newString;
}

console.log('written with FOR LOOP: ' + repeatStringNumTimes("abc", 3));

Now you can even do something like this:

console.log('written with FOR LOOP: ' + repeatStringNumTimes(repeatStringNumTimes("abc", 3), 3));

Step 4.4

OK

Step 4.5

freeCodeCamp uses var instead of let and const. Just remember, if you have a choice then use let and const.

You can use the short-cut form of product *= arr[i][j].

Step 4.6

You can solve the n-dimensions problem with a recursive function (google for it). See the solution I posted in slack.

Step 4.7

Your conclusions are correct.

Step 5

OK

bonus

This is a bit of bismillah code.

'use strict';
let mainArr = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c'];
mainArr.getUnique = function () {
    let o = {}, uniqArr = [], mainArrItem;
    for (let i = 0; mainArrItem = this[i]; i++) {
        o[mainArrItem] = 1
    };
    for (mainArrItem in o) {
        uniqArr.push(mainArrItem)
    };
    return uniqArr;
}
console.log(mainArr.getUnique());

I had to run it in the debugger to see what is happening. First of all, the loop condition in your first for loop is actually an assignment (because of the single =). So this loop iterates until i is equal to the length of mainArray. After that this[i] becomes undefined which causes this loop to terminate.

I can see that you are exploiting the fact that object keys are unique. A simpler way would be to use an ES6 Set().

The next thing I saw is that you add a method to an existing array. Perhaps this was just an experiment, but for real code this just unnecessarily complicates the code.

Sam's feedback

Hi Elmira,

Very well done dear, your code looks neat and clean, and it is working. I only have one comment:
In line No. 7, you can remove the newNumber = newNumber.map...... Instead, you can just do it in one line as following:
newNumber = number.filter(arrNumbers => (arrNumbers % 2 !== 0)).map( doubledNumbers => ( doubledNumbers * 2));
This gives you the same result.

Wish you a lovely evening!

anas almostafa

Dear Elmira
you do a great job and and clean code, but I realy I do't understand the code in bonus.js maybe can you explain it to me later.

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.