We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6dc4a7c commit 6927a96Copy full SHA for 6927a96
exercises/107-getLengthOfLongestElement/solution.hide.js
@@ -1,12 +1,18 @@
1
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;
+ // your code here
+ if (arr.length === 0) {
+ return 0;
+ }
+
+ let longestLength = 0;
8
+ for (let i = 0; i < arr.length; i++) {
9
+ if (arr[i].length > longestLength) {
10
+ longestLength = arr[i].length;
11
}
12
13
14
+ return longestLength;
15
16
17
let output = getLengthOfLongestElement(['one', 'two', 'three']);
-console.log(output); // --> 5
18
+console.log(output); // --> 5
0 commit comments