0
  1. How to import into function an existing function that I have alreqdy created before ?

  2. How to import into function an array ?

function namarray (arr[])
{}

function namfunc (fun())
{}

How to write it in right syntax ?

7
  • The term "absorb into function" does not make sense. Commented Nov 15, 2019 at 23:45
  • Explain, what you want to achieve? Commented Nov 15, 2019 at 23:46
  • Seems like maybe you're interested in how to pass a reference to a function into another function and a reference to an array into a function? Commented Nov 15, 2019 at 23:47
  • Maybe the right word is imoort ? Commented Nov 15, 2019 at 23:50
  • Like this: function (name) and than you can send to the function any variable you want when you apply the function on real variable you have created. Commented Nov 15, 2019 at 23:52

1 Answer 1

3

It's the same in both cases, you're passing what you want as an argument to the function. With a function, you're just passing the function name, so don't include the () - you use that later when you want to invoke the function

You can of course choose to save your inputs to variables inside the function

// 1) How to import into function an existing function that I have alreqdy created before ?
// 2) How to import into function an array ?

function testFunction () {
  return 'I am the test function';
}

function questionOne (input) {
  console.log(input());
}

function questionTwo (input) {
  console.log(`I was given the input ${input}, which is an ${typeof input}`);
}

questionOne(testFunction);
questionTwo([1,2,3]);

// In reply to comment
let longArray = [1,2,3,4,5,6,7,8,9,11,22,33,44,55,66,77,88,99,111,222,333];
questionTwo(longArray); 

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

2 Comments

thank you very much. But if the array is very long, can't you just write the array name or something ?
Yes, Absolutely

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.