JS encontra uma palavra mais longa na função de string
function findLongestWordLength(str) {
return Math.max(...str.split(' ').map(word => word.length));
}
Tiger King
function findLongestWordLength(str) {
return Math.max(...str.split(' ').map(word => word.length));
}
function data(str){
var show = str.split(" ");
show.sort(function (a,b){
return b.length - a.length;
})
return show[0];
}
console.log(data(str = "javascript is my favourite language "));
const wordsArray = ['1', '22', '222', 'longstring', '2222']
const longestWord = wordsArray.reduce((longestWord, currentWord) =>
currentWord.length > longestWord.length ? currentWord: longestWord, '');
console.debug(longestWord); // longstring