Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
How can you calculate number of functions in a module when exporting/importing a custom module

Taking an instance of exporting these two functions in JS

module.js

const add = (a,b) => {
    return a+b;
};

const sub = (a,b) => {
    return a-b;
};

module.exports = {add, sub};

new.js

const {add, sub} = require('./module');

console.log(add(5,4));
console.log(sub(5,4));

Help, if I was to count how many functions am I importing on new.js file.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It would be interesting to know what you are trying to achieve as it is somewhat unusual, but it should be somewhat easy to get what you are after.

You can for example import everything from './module' as an object and then count the keys or similar in the imported object to get number of functions.

So for example:

const importedFunctions = require('./module');

console.log(Object.keys(importedFunctions).length)

Edit: I saw your reply in the comments. To extend it a bit further to call all imported functions with some values you could do something like this:

Object.values(importedFunctions).forEach((fn) => fn(5, 4))
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda