Javascript: Length of last word

JS: Arrays
Last update: 09 Jul 23:20
1
Student
100%
Completion rate

solution.js

Write and export as default a function returns the length of the last word of an input string. Word is any sequence of characters without gaps (spaces).

import getLastWordLength from './solution.js';

getLastWordLength(''); // 0

getLastWordLength('man in BlacK'); // 5

getLastWordLength('hello, world!  '); // 6

Tips

  • To remove extra spaces use trim method

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests