Web Developer
8.49K subscribers
135 photos
3 videos
10 files
33 links
Books
YT Channels
Articles
Courses
Notes

👥 Group : @Web_developersz
Download Telegram
Javascript Reduce method Example.

▫️ 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