✅ Javascript Reduce method Example.
▫️ Finding the longest word in a given string.
#JavaScript #Reduce
(👥) • @Web_developersz
(📚) • @Web_developerszz
▫️ Finding the longest word in a given string.
function longerWord(a, b) {
if (a.length > b.length) {
return a;
} else {
return b;
}
}
const sentence = 'Hey there what are you doing this Wednesday night';
const longest = sentence.split(' ').reduce(longerWord);
console.log(longest);
// Wednesday
#JavaScript #Reduce
(👥) • @Web_developersz
(📚) • @Web_developerszz