Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda