Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

64 lines
1.4 KiB
Markdown

---
id: 699c8e045ee7cb94ed2322d4
title: "Challenge 213: Word Length Converter"
challengeType: 28
dashedName: challenge-213
---
# --description--
Given a string of words, return a new string where each word is replaced by its length.
- Words in the given string will be separated by a single space
- Keep the spaces in the returned string.
For example, given `"hello world"`, return `"5 5"`.
# --hints--
`convertWords("hello world")` should return `"5 5"`.
```js
assert.equal(convertWords("hello world"), "5 5");
```
`convertWords("Thanks and happy coding")` should return `"6 3 5 6"`.
```js
assert.equal(convertWords("Thanks and happy coding"), "6 3 5 6");
```
`convertWords("The quick brown fox jumps over the lazy dog")` should return `"3 5 5 3 5 4 3 4 3"`.
```js
assert.equal(convertWords("The quick brown fox jumps over the lazy dog"), "3 5 5 3 5 4 3 4 3");
```
`convertWords("Lorem ipsum dolor sit amet consectetur adipiscing elit donec ut ligula vehicula iaculis orci vel semper nisl")` should return `"5 5 5 3 4 11 10 4 5 2 6 8 7 4 3 6 4"`.
```js
assert.equal(convertWords("Lorem ipsum dolor sit amet consectetur adipiscing elit donec ut ligula vehicula iaculis orci vel semper nisl"), "5 5 5 3 4 11 10 4 5 2 6 8 7 4 3 6 4");
```
# --seed--
## --seed-contents--
```js
function convertWords(str) {
return str;
}
```
# --solutions--
```js
function convertWords(str) {
return str
.split(" ")
.map(word => word.length)
.join(" ");
}
```