scrimba
Clean Code
Avoiding Comments with Refactoring
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Avoiding Comments with Refactoring
AboutCommentsNotes
Avoiding Comments with Refactoring
Expand for more info
index.js
run
preview
console
// gets all longest strings
function longestString(inputArray) {
// initialize the longest string to first value
let length = inputArray[0].length;

for (let i = 1; i < inputArray.length; i++) {
// checks if current string is longer than current longest
if(length < inputArray[i].length) {
length = inputArray[i].length;
}
}

// filters out any values not equal to the longest string
const strs = inputArray.filter((word) => word.length === length);

return strs;
}
Console
/index.html
-3:28