Giter Site home page Giter Site logo

fm-snippets's People

Contributors

1marc avatar dtauer avatar joshhogg avatar laniehei avatar pabloppizarro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fm-snippets's Issues

Issue in challenge 23 of callback.js file

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 intersection solution is not correct

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])

Challenge 3 Part 2 solution is not correct

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!

intersection doesn't look at all arrays

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

Comment Questions in the solutions file.

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.

challenge 9

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' }

[JavaScript the Hard Parts] Refactor intersection to use reduce

How to refactor intersection code as suggested @ CSBin so that it uses reduce?

See code here

// Extension 3 //
function intersection(arrays) {
//note: 'arguments' is a built-in object corresponding, in this case, to what was passed in for arrays
let result = [];
for (let k = 1; k < arguments.length - 1; k++) { //loops through arrays
//console.log(arrays[k]);
for (let i = 0; i < arguments[0].length; i++) { //loops through first array
for (let j = 0; j < arguments[k].length; j++) { //loops through k'th array
if (arguments[0][i] === arguments[k][j]) { //checks if the value is the same as in the first array
if (!result.includes(arguments[0][i])) { //checks if number is already noted
result.push(arguments[0][i]) //adds the number to our array with elements in all arrays
}
}
}
}
}
return result;
}
console.log(intersection([5, 10, 15, 20], [15, 88, 1, 5, 7], [1, 10, 15, 5, 20]));
// should log: [5, 15]

Issue in Challenge 4 in callbacks.js

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.

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.