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

188
Visualizações
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 Respostas
Responde à pergunta

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 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