2021-02-06 04:42:36 +00:00
|
|
|
---
|
|
|
|
id: a26cbbe9ad8655a977e1ceb5
|
2021-02-16 15:21:30 -07:00
|
|
|
title: Encuentra la palabra más larga en una cadena
|
2021-02-06 04:42:36 +00:00
|
|
|
challengeType: 5
|
|
|
|
forumTopicId: 16015
|
|
|
|
dashedName: find-the-longest-word-in-a-string
|
|
|
|
---
|
|
|
|
|
|
|
|
# --description--
|
|
|
|
|
2021-02-16 15:21:30 -07:00
|
|
|
Devuelve la longitud de la palabra más larga en la oración proporcionada.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
2021-02-16 15:21:30 -07:00
|
|
|
Tu respuesta debe ser un número.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
2021-02-16 15:21:30 -07:00
|
|
|
`findLongestWordLength("The quick brown fox jumped over the lazy dog")` debe devolver un número.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(
|
|
|
|
typeof findLongestWordLength(
|
|
|
|
'The quick brown fox jumped over the lazy dog'
|
|
|
|
) === 'number'
|
|
|
|
);
|
|
|
|
```
|
|
|
|
|
2021-03-16 08:41:19 -06:00
|
|
|
`findLongestWordLength("The quick brown fox jumped over the lazy dog")` debe devolver `6`.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(
|
|
|
|
findLongestWordLength('The quick brown fox jumped over the lazy dog') === 6
|
|
|
|
);
|
|
|
|
```
|
|
|
|
|
2021-03-16 08:41:19 -06:00
|
|
|
`findLongestWordLength("May the force be with you")` debe devolver `5`.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(findLongestWordLength('May the force be with you') === 5);
|
|
|
|
```
|
|
|
|
|
2021-03-16 08:41:19 -06:00
|
|
|
`findLongestWordLength("Google do a barrel roll")` debe devolver `6`.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(findLongestWordLength('Google do a barrel roll') === 6);
|
|
|
|
```
|
|
|
|
|
2021-03-16 08:41:19 -06:00
|
|
|
`findLongestWordLength("What is the average airspeed velocity of an unladen swallow")` debe devolver `8`.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(
|
|
|
|
findLongestWordLength(
|
|
|
|
'What is the average airspeed velocity of an unladen swallow'
|
|
|
|
) === 8
|
|
|
|
);
|
|
|
|
```
|
|
|
|
|
2021-03-16 08:41:19 -06:00
|
|
|
`findLongestWordLength("What if we try a super-long word such as otorhinolaryngology")` debe devolver `19`.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(
|
|
|
|
findLongestWordLength(
|
|
|
|
'What if we try a super-long word such as otorhinolaryngology'
|
|
|
|
) === 19
|
|
|
|
);
|
|
|
|
```
|
|
|
|
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```js
|
|
|
|
function findLongestWordLength(str) {
|
|
|
|
return str.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
findLongestWordLength("The quick brown fox jumped over the lazy dog");
|
|
|
|
```
|
|
|
|
|
|
|
|
# --solutions--
|
|
|
|
|
|
|
|
```js
|
|
|
|
function findLongestWordLength(str) {
|
|
|
|
return str.split(' ').sort((a, b) => b.length - a.length)[0].length;
|
|
|
|
}
|
|
|
|
|
|
|
|
findLongestWordLength("The quick brown fox jumped over the lazy dog");
|
|
|
|
```
|