zydan1 / hyf-javascript2 Goto Github PK
View Code? Open in Web Editor NEWJavaScript Module 2
JavaScript Module 2
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.
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
Hi Hamza, here is my feedback on your homework.
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);
While the code works, the approach you have taken for testing divisibility is a bit convoluted:
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]);
}
Missing
Missing
Missing
See the solution that I posted in slack shows how you can do this with a recursive function.
I'm not entirely sure, but I think you understand the difference between call by value and call by reference.
OK, but you can replace +=
by simply +
because the value of x
is not used after the return
statement.
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));
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.