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

118
Vistas
How do I return an object of word and its length from an array of words?

Given an array of strings, return an object containing a key for every different string in the array, and the value is that string's length.

wordLen(["a", "bb", "a", "bb"])          → { "bb": 2, "a": 1 }
wordLen(["this", "and", "that", "and"])  → { "that": 4, "and": 3, "this": 4 }
wordLen(["code", "code", "code", "bug"]) → { "code": 4, "bug": 3 }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

var arr = ["a", "bb", "a", "bb"];
var entries = arr.map(x => [x, x.length]);
console.log(Object.fromEntries(entries));

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can loop through the array and store each word length in an object with the word itself being the key

function wordLen(arr){
    let words = {};
    arr.forEach(word => words[word] = word.length);
    return words;
}

Non-ES6

function wordLen(arr){
    var words = {};
    arr.forEach(function(word){ words[word] = word.length });
    return words;
}
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