Skip to content
Advertisement

Tag: function

JavaScript – for Loop vs. Array shift

I have two functions, they do look alike but what I don’t really understand is when inside the for-loop, since the input is an array, why doesn’t the array need any index to call the first array? I have an array of… I’m trying to loop through the array with an input. The result of the first function will then

Can you bind ‘this’ in an arrow function?

I’ve been experimenting with ES6 for a while now, and I’ve just come to a slight problem. I really like using arrow functions, and whenever I can, I use them. However, it would appear that you can’t bind them! Here is the function: Here is the object I want to bind the function to: And here is how I would

Javascript function challenge add(1,2) and add(1)(2) both should return 3

A friend of mine challenged me to write a function that works with both of these scenarios My instinct was the write an add() function that returns itself but I’m not sure I’m heading in the right direction. This failed. So I started reading up on functions that return other functions or return themselves. http://davidwalsh.name/javascript-functions JavaScript: self-calling function returns a

Iterative solution for flattening n-th nested arrays in Javascript

Can anyone show me an iterative solution for the following problem? I solved it recursively but struggled with an iterative solution. (Facebook Technical Interview Question) Solution must work with n-th nested array elements (i.e. it must still work if someone modifies the array values/placement in the example above) Recursive solution: Answer Here is one way: Explanation: If iterating over a

financial rate function in javascript not working properly

the function given at simple financial rate function in javascript is not giving me same answers as excel rate function some time. It works perfectly for the problem given at http://allfinancialmatters.com/2009/11/03/how-to-use-the-rate-function-in-excel/ but for my test cases. its results are different from excel rate. this is strange behaviour. i am unable to sort this out. my test cases (with excel output)

Advertisement