Files
freeCodeCamp/curriculum/challenges/ukrainian/22-rosetta-code/rosetta-code-challenges/longest-string-challenge.md
camperbot 7a0d396180 chore(i18n,learn): processed translations (#53415)
Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2024-02-13 18:31:01 +01:00

102 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
id: 5e6dd14192286d95fc43046e
title: Найдовший рядок
challengeType: 1
forumTopicId: 385275
dashedName: longest-string-challenge
---
# --description--
У цьому завданні вам потрібно знайти рядки, які є найдовшими серед наданих.
# --instructions--
Напишіть функцію, яка приймає масив рядків і повертає рядки, довжина яких є найдовшою.
# --hints--
`longestString` має бути функцією.
```js
assert(typeof longestString == 'function');
```
`longestString(["a", "bb", "ccc", "ee", "f", "ggg"])` має повернути масив.
```js
assert(Array.isArray(longestString(['a', 'bb', 'ccc', 'ee', 'f', 'ggg'])));
```
`longestString(["a", "bb", "ccc", "ee", "f", "ggg"])` має повернути `["ccc", "ggg"]`.
```js
assert.deepEqual(longestString(['a', 'bb', 'ccc', 'ee', 'f', 'ggg']), [
'ccc',
'ggg'
]);
```
`longestString(["afedg", "bb", "sdccc", "efdee", "f", "geegg"])` має повернути `["afedg", "sdccc", "efdee", "geegg"]`.
```js
assert.deepEqual(
longestString(['afedg', 'bb', 'sdccc', 'efdee', 'f', 'geegg']),
['afedg', 'sdccc', 'efdee', 'geegg']
);
```
`longestString(["a", "bhghgb", "ccc", "efde", "fssdrr", "ggg"])` має повернути `["bhghgb", "fssdrr"]`.
```js
assert.deepEqual(
longestString(['a', 'bhghgb', 'ccc', 'efde', 'fssdrr', 'ggg']),
['bhghgb', 'fssdrr']
);
```
`longestString(["ahgfhg", "bdsfsb", "ccc", "ee", "f", "ggdsfg"])` має повернути `["ahgfhg", "bdsfsb", "ggdsfg"]`.
```js
assert.deepEqual(
longestString(['ahgfhg', 'bdsfsb', 'ccc', 'ee', 'f', 'ggdsfg']),
['ahgfhg', 'bdsfsb', 'ggdsfg']
);
```
`longestString(["a", "bbdsf", "ccc", "edfe", "gzzzgg"])` має повернути `["gzzzgg"]`.
```js
assert.deepEqual(longestString(['a', 'bbdsf', 'ccc', 'edfe', 'gzzzgg']), [
'gzzzgg'
]);
```
# --seed--
## --seed-contents--
```js
function longestString(strings) {
}
```
# --solutions--
```js
function longestString(strings) {
var mx = 0;
var result = []
strings.forEach(function (e) {
if (e.length > mx) {
mx = e.length
result = [e]
} else if (e.length == mx)
result.push(e)
})
return result
}
```