Skip to content
Advertisement

How to return an array of numbers that represent lengths of elements string?

If an array was: [‘hey’, ‘you’, ‘muddy’] The expected output should be: [3, 3, 5]

This is what I have so far:

JavaScript

Any help would be much appreciated.

Advertisement

Answer

You need to push the length of every item (using Array#push) and return the array in the end:

JavaScript

Another solution using Array#map:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement