✅ Javanoscript 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
(📚) • @WebsiteDesignLearningGroup
▫️ 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
(📚) • @WebsiteDesignLearningGroup
👍6🔥1
What will be the output of the following code? console.log(2 + "2" - 1);
Anonymous Quiz
32%
21
33%
"21"
29%
3
7%
11
👍3🤣3❤2
👍2