Ask Question
10 July, 12:45

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

+3
Answers (1)
  1. 10 July, 13:42
    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?
Find an answer to your question ✅ “function getLongestString (strings) { } / * Do not modify code below this line * / const strings = ['long', 'longer', 'longest']; console. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers