frontendmasters / fm-snippets Goto Github PK
View Code? Open in Web Editor NEWCode snippets for course annotations.
Code snippets for course annotations.
do we need to define step here?
wouldn't be sufficient to have the function like this
function addByX(x) {
function addBy(input) {
return input + x
}
return addBy
}
The following solution, although it's correct, does not seem to be working for me:
I get the following error:
Type Error on line 132: mike.introduce is not a function
in the If case, the solution code is returning 1 directly instead of the index of the current element(i) as mentioned in the problem statement.
The challenge description:
Define a function myFunc that takes an array and a callback. myFunc should pass each element from the array (in order) into the callback. If the callback returns true, myFunc should return the index of the current element. If the callback never returns true, myFunc should return -1;
Below is the code mentioned in the solution:
function myFunc(array, callback) {
for (let i = 0; i < array.length; i++) {
if (callback(array[i])) return 1;
}
return -1;
}
The current solution for the intersection only works with two arrays.
The -1 from the length means there will always be one item left in the array.
for (let k = 1; k < arguments.length - 1; k++)
The condition only checks the item of first array against the other arrays in sequence, if an item from any array matches an item from the first array it will return true. There is no check for an item to exist in all array.
if (arguments[0][i] === arguments[k][j])
The Challenge 3 Part 2 solution does not accurately imitate the behavior of setInterval
. I found something like:
const sayHowdy = () => console.log("Howdy")
function everyXsecsForYsecs(callback, intervalTime, totalTime) {
for (let i = 0; i < totalTime/intervalTime; i++) {
setTimeout(sayHowdy, (intervalTime * (1000 * i)))
}
}
everyXsecsForYsecs(sayHowdy, 3, 13) // howdy logs 5 times
everyXsecsForYsecs(sayHowdy, 3, 20) // howdy logs 7 times
This solution is obviously going to be somewhat inaccurate when it comes to running the callback function PRECISELY as many times as you'd want it to, but the behavior is much closer to setInterval
I think.
Anyone please correct me if I'm wrong!
The solution to part2 of challenge 3 in asynchronocity exercise in hardparts doesn't work as expected. It doesn't print "Howdy" messages at the interval of 2 seconds. It print all 5 at the sametime after the "End of Challenge 3" message gets logged.
Hi, in the solution you are missing part of the assignment that says to pass any arguments after wait to the callback function.
intersection will not look at last array because you substract 1 from length of arguments. If you had 4 arrays which would be similar to removing the -1 on arguments, the solution produces a result with numbers not
in second array
Presently, I am working on the closure.js file in the javascript-hard-parts, I think it would be preferable to have the questions commented above the solutions provided just for easier learning. Thank you.
In challenge 9, it doesn't log what it is considered to.
should log: { hi: 'HI', bye: 'BYE', later: 'LATER' } but logs {bye: 'BYE', later: 'LATER' }
How to refactor intersection
code as suggested @ CSBin so that it uses reduce
?
The description of the challenge states that the function must not return anything.
Challenge 4 decription:
Create a function called forEach that takes an array and a callback, and runs the callback on each element of the array. forEach does not return anything.
However the solution clearly has a return keyword.
Challenge 4 solution:
function forEach(array, callback) {
let arr = []
for(let i=0; i<array.length; i++) {
arr.push(callback(array[i]))
}
return arr
}
Also for challenge 5, the definition states that I should use the forEach however without forEach returning the challenge is not possible.
Challenge 5 decription:
In challenge 3, you've created a function called map. In this challenge, you're going to rebuild the map function by creating a function called mapWith. This time you're going to use forEach inside of mapWith instead of using a for loop.
I don't know whether the challenges description are wrong or the provided solution but there is a mismatch.
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.