Q:

Write a JavaScript to find the longest string from a given array of strings

0

Write a JavaScript to find the longest string from a given array of strings.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

function longest_string(str_ara) {
  var max = str_ara[0].length;
  str_ara.map(v => max = Math.max(max, v.length));
  result = str_ara.filter(v => v.length == max);
  return result;
}

console.log(longest_string(['a', 'aa', 'aaa',
                                          'aaaaa','aaaa']))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now