0

Two tasks given to me seem difficult to understand, and before completing the tasks to what I think the module leader wants, can anyone else wrap their head around these?

  1. Create a function called "hasMatch" that accepts a function and a list and returns true if the function returns true for at least one item in the list, and false otherwise. Does your function work polymorphically (e.g. on numbers and strings)?
  2. Write a function that will take a number as argument and return a new function that also takes a number: when the new function is called it returns the sum of its argument and the original number.

If you are able to give examples to better explain, that would be much appreciated.

EDIT: I obviously don't want absolute answers for me to take, just want an explanation to what the question means as I am struggling to understand what the leader wants.

1
  • welcome to SO! you might need to ask a more specific question to get a good response, what implementation constraints do you have? what have you tried so far? etc... see stackoverflow.com/help/how-to-ask Commented Dec 31, 2017 at 3:44

1 Answer 1

1
function hasMatch( function , list) {
// actually calling the function next line
if (function (list)=== true ){
return true}
else return false;
}

In order to make your function operate with different types of parameters such as strings and numbers which are usually considered primitives you have to overload your function; which means you create different function implementations depending on argument type. What is possible all depends upon what language you are writing code in.

Sign up to request clarification or add additional context in comments.

3 Comments

So if I'm understanding correctly, write a function which takes in other functions to see if it matches a criteria, and to also check what argument type it is? Can you give me an example on when this might be useful?
so the language I chose was javascript, but I will also need to write the same functions in other languages to compare.
so in javascript there is no true overloading, so you would put comparison syntax for argument types in the logic of the function like isInt(argument)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.