-
Notifications
You must be signed in to change notification settings - Fork 0
/
task-03.js
40 lines (28 loc) · 1.07 KB
/
task-03.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"use strict";
const findLongestWord = function(string) {
const words = string.split(" ");
let longestWord = words[0];
for (let i = 1; i < words.length; i++) {
if (words[i].length > longestWord.length) {
longestWord = words[i];
}
}
return longestWord;
};
console.log(findLongestWord("The quick brown fox jumped over the lazy dog")); // 'jumped'
console.log(findLongestWord("Google do a roll")); // 'Google'
console.log(findLongestWord("May the force be with you")); // 'force'
// ======================ВТОРОЙ ВАРИАНТ РЕШЕНИЯ
// const findLongestWord = function(string) {
// const words = string.split(" ");
// let longestWord = words[0];
// for (const word of words) {
// if (word.length > longestWord.length) {
// longestWord = word;
// }
// }
// return longestWord;
// };
// console.log(findLongestWord("The quick brown fox jumped over the lazy dog")); // 'jumped'
// console.log(findLongestWord("Google do a roll")); // 'Google'
// console.log(findLongestWord("May the force be with you")); // 'force'