--- id: 5e6dd14192286d95fc43046e title: Longest string challenge challengeType: 5 isHidden: false --- ## Description
In this challenge, you have to find the strings that are the longest among the given strings.
## Instructions
Write a function that takes an array of strings and returns the strings that have a length equal to the longest length.
## Tests
``` yml tests: - text: longestString should be a function. testString: assert(typeof longestString == 'function'); - text: longestString(["a", "bb", "ccc", "ee", "f", "ggg"]) should return a array. testString: assert(Array.isArray(longestString(["a", "bb", "ccc", "ee", "f", "ggg"]))); - text: longestString(["a", "bb", "ccc", "ee", "f", "ggg"]) should return ["ccc", "ggg"]'. testString: assert.deepEqual(longestString(["a", "bb", "ccc", "ee", "f", "ggg"]), ["ccc", "ggg"]); - text: longestString(["afedg", "bb", "sdccc", "efdee", "f", "geegg"]) should return ["afedg", "sdccc", "efdee", "geegg"]. testString: assert.deepEqual(longestString(["afedg", "bb", "sdccc", "efdee", "f", "geegg"]), ["afedg", "sdccc", "efdee", "geegg"]); - text: longestString(["a", "bhghgb", "ccc", "efde", "fssdrr", "ggg"]) should return ["bhghgb", "fssdrr"]. testString: assert.deepEqual(longestString(["a", "bhghgb", "ccc", "efde", "fssdrr", "ggg"]), ["bhghgb", "fssdrr"]); - text: longestString(["ahgfhg", "bdsfsb", "ccc", "ee", "f", "ggdsfg"]) should return ["ahgfhg", "bdsfsb", "ggdsfg"]. testString: assert.deepEqual(longestString(["ahgfhg", "bdsfsb", "ccc", "ee", "f", "ggdsfg"]), ["ahgfhg", "bdsfsb", "ggdsfg"]); - text: longestString(["a", "bbdsf", "ccc", "edfe", "gzzzgg"]) should return ["gzzzgg"]. testString: assert.deepEqual(longestString(["a", "bbdsf", "ccc", "edfe", "gzzzgg"]), ["gzzzgg"]); ```
## Challenge Seed
```js function longestString(strings) { } ```
## Solution
```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 } ```