From 487404722d9cf2b19c99a1f4c7dcc635f18887e2 Mon Sep 17 00:00:00 2001 From: Martin Krause Date: Tue, 2 Nov 2021 18:11:56 +0200 Subject: [PATCH] fix(Array/lontestString): fix function, fix test --- src/array/longest-string.js | 2 +- test/array/longest-string.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/array/longest-string.js b/src/array/longest-string.js index 0e66e0e..fc9561e 100644 --- a/src/array/longest-string.js +++ b/src/array/longest-string.js @@ -3,6 +3,6 @@ * @param {Array} arr * @returns {String} */ -const fn = arr => arr => Math.max(...arr.map((el) => el.length)); +const fn = arr => arr.reduce((prev, curr) => prev.length > curr.length ? prev : curr); export default fn; \ No newline at end of file diff --git a/test/array/longest-string.spec.js b/test/array/longest-string.spec.js index c7440f7..21854c8 100644 --- a/test/array/longest-string.spec.js +++ b/test/array/longest-string.spec.js @@ -5,7 +5,7 @@ const test = require('ava'); test('returns the only item if the array has only one item', t => { let input = ['foo']; let expectation = 'foo'; - t.equals(longestString(input), expectation); + t.is(longestString(input), expectation); }); test('returns the longest string entry from the array', t => {