Question Bank

JavaScript String Lengths Array: Four Approaches Quiz

Difficulty: Medium

Four seeded ways to turn an array of strings into an array of their lengths (map, for-loop with push, reduce, for-of), plus one companion on a recursive variant.

Question Bank
/

JavaScript String Lengths Array: Four Approaches Quiz

JavaScript String Lengths Array: Four Approaches Quiz

Four seeded ways to turn an array of strings into an array of their lengths (map, for-loop with push, reduce, for-of), plus one companion on a recursive variant.

Question Bank
Medium
JavaScript
5 questions
quiz
arrays
map-filter-reduce
fundamentals

253 views

5

Implement getLength(arr) using Array.prototype.map so it returns the lengths of each string in order.

Examples

Example 1:

Input: getLength(['hi', 'my', 'name is', 'john'])
Output: [2, 2, 7, 4]
Explanation: map applies v.length to every element and produces a same-length array.