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

189
Vistas
inserting a value into an object and returning the value

I am trying provide a function (wrap) that inserts a value into an object in JS and return that value. So if wrap('mystring') is called, 'mystring' should be returned. If wrap(345) is called, 345 (I believe as an integer) should be called and so on and so forth (don't think I need to return an array).

I just want to put the value inside of an object and then to return that value. So the object should be {key: 10} or {key: 'Mine'} and just return the value itself (so return 10 as an integer or return 'Mine" as a string ).

This is my code:


function wrap(value) {
  let obj = {}
  const key = value;
  obj[key] = value;
  return obj
}

Test Passed: Value == 'object';
Expected: 'MyTest', instead got: undefined;
Expected: 343, instead got: undefined;
Expected: { test: 'testy' }, instead got: undefined;

These are the tests, and three of the tests are not passed.

Any help is appreciated, Thank you

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your function works i have this

function wrap(value) {
  let obj = {}
  // const key = value;
  // obj[key] = value;
  obj['key'] value;
  return obj
}
console.log(wrap(10)) 
// returns {key: 10} 
console.log(wrap('Mine') 
// returns {key: 'Mine'}

It this clearly what you want to do ? Just define the function doesn't execute it.

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