Skip to content

Commit eb19002

Browse files
author
Ivan Rubio
committed
2n advance
1 parent 3a70d55 commit eb19002

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

src/functions-and-arrays.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
// Iteration #1: Find the maximum
2-
/ Iteration #1: Find the maximum
32
function maxOfTwoNumbers(num1, num2) {
4-
if(num1>num2){
5-
let caja=[num1,num2]
6-
caja.sort()
7-
let bigger=caja[1]
8-
return console.log(bigger)
9-
}
3+
if (num1 > num2) {
4+
let caja = [num1, num2];
5+
caja.sort();
6+
let bigger = caja[1];
7+
return bigger;
8+
}
109
return num2;
1110
}
12-
maxOfTwoNumbers(1,3);
11+
// maxOfTwoNumbers(2, 1);
1312

1413
// Iteration #2: Find longest word
1514
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
15+
// let words = ['a', 'zab', '12abc', '$$abcd', 'abcde', 'ironhack'];
16+
function findLongestWord(array1) {
17+
if (array1.length == 0) {
18+
return null;
19+
} else if (array1.length === 1) {
20+
return array1[0]
21+
} else if (array1.length > 1) {
22+
let longest = " ";
23+
24+
array1.forEach(function(word) {
25+
if (word.length > longest.length) {
26+
word = longest;
27+
}
28+
console.log(word);
29+
}
30+
);
31+
}
32+
}
1633

17-
function findLongestWord(array1){
18-
typeof array1 === ‘null’;
34+
findLongestWord(words);
1935

2036
// Iteration #3: Calculate the sum
2137

test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
2+
let words = ['a', 'zab', '12abc', '$$abcd', 'abcde', 'ironhack'];
3+
4+
function findLongestWord(array1) {
5+
if (array1.length == 0) {
6+
return null;
7+
} else if (array1.length === 1) {
8+
return array1[0]
9+
} else if (array1.length > 1) {
10+
let longest = " ";
11+
12+
array1.forEach(function(word) {
13+
14+
console.log(word);
15+
if (word.length > longest.length) {
16+
word = longest;
17+
}
18+
console.log(word);
19+
20+
21+
}
22+
23+
24+
25+
26+
);
27+
28+
}
29+
}
30+
findLongestWord(words)

0 commit comments

Comments
 (0)