JavaScript Algorithm Scripting -- Best Practice?

I’m doing one of the challenges on Basic Algorithm Scripting in JavaScript. My code passes all the test and it looks good to me, but it was not included in any of the solutions for the problem help. Can anyone tell me if my code is poorly written or is considered bad practice for any reason?

Hi @nteferra

Welcome to FCC. It is not possible to provide all possible solutions for a challenge. There are many ways of solving the same problem. The solutions in the help section are given so that you can use them to improve yours. They also give you techniques of solving the same problem that you haven’t thought about.

There is no problem even if your solution is not listed among the possible solutions given. Yours could even be better than the possible solutions given. Your solution above looks correct and readable to me. As long as it passes the tests, there shouldn’t be any reason to worry about.

Though one thing I suggest you do is to add spacing between statements(groups of statements) to increase readability. You can see the single spacing between the variable declaration, for loop, and the return statement.

function largestOfFour(arr){
  let largest = [];

  for(let i = 0; i < arr.length; i++) {
  }

  return largest;
}
1 Like

Ok, thank you for the feedback!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.