Ask Question
24 April, 06:52

function getLongestString (strings) { } / * Do not modify code below this line * / const strings = ['long', 'longer', 'longest']; console. log (getLongestString (strings), '<- - should be "longest"');

+5
Answers (1)
  1. 24 April, 09:12
    0
    function getLongestString (strings) {

    return strings. reduce ((acc, cur) = > acc. length > cur. length? acc : cur);

    }

    Explanation:

    A reducer applies the same operation to each array element. In this case, the longest string is stored in the accumulator (acc), and is replaced only by the current element (cur) if the current element is longer than the accumulator.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “function getLongestString (strings) { } / * Do not modify code below this line * / const strings = ['long', 'longer', 'longest']; console. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers