Skip to content

Commit 6927a96

Browse files
authored
Update solution.hide.js
1 parent 6dc4a7c commit 6927a96

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
function getLengthOfLongestElement(arr) {
2-
// Your code here
3-
if (arr.length < 1) return 0
4-
else {
5-
let aux = 0
6-
arr.map(item=> item.length > aux ? aux = item.length : null)
7-
return aux;
2+
// your code here
3+
if (arr.length === 0) {
4+
return 0;
5+
}
6+
7+
let longestLength = 0;
8+
for (let i = 0; i < arr.length; i++) {
9+
if (arr[i].length > longestLength) {
10+
longestLength = arr[i].length;
811
}
12+
}
13+
14+
return longestLength;
915
}
1016

1117
let output = getLengthOfLongestElement(['one', 'two', 'three']);
12-
console.log(output); // --> 5
18+
console.log(output); // --> 5

0 commit comments

Comments
 (0)