Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Map to Lengths

Working With Arraysmedium

Course · Section 11: Working With Arrays · Lecture 156: Data Transformations: map, filter, reduce

Implement `wordLengths(words)` returning the length of each string, using `map`.

Sample tests

Input: wordLengths(["a","abc","ab"])
Output: [1,3,2]
Input: wordLengths([])
Output: []

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Calling .length on a non-string if the data is mixed.

Learning resources

  • MDN: Array iteration methods
Approach & explanation (try first)

map turns the list of strings into a list of their lengths.

Loading...
⌘/Ctrl + Enter

Run your code to see results.