Ask Question

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

+1
Answers (1)
  1. 23 July, 15:50
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers