I'm a beginner trying to rewrite the underline function _.invoke
.
I'm trying to create the function so that it returns an array containing the results of calling the method on each value in the collection.
_.invoke = function(collection, methodName) { var result = []; if (Array.isArray(collection)) { for (let i = 0; i < collection.length; i++) { methodName.call(collection[i]) var value = collection[i][methodName] result.push(value) } } return result }
I think my problem is with this line:
methodName.call(collection[i])
- Want to call a method on object collection[i]
, but I want to pass some parameters if they are included in the unit test ).
So far I have tried using the test: typeof(methodName) === "function"
and writing a function to test if the method is a function.
Here you can call with parameters.
There is a method to test all projects:
Is this what you mean?