DEV Community

Discussion on: Error Handling: Read the console output!

Collapse
 
jdforsythe profile image
Jeremy Forsythe

A couple other helpful tips for you:

  • use const or let instead of var
  • there's no need to declare the vars at the top of the function - e.g. just declare num on the input.match line
  • you likely don't need a result variable - 99% of the time you can just return a value directly and it tends to lead to cleaner code - for instance you'll find yourself writing "else" a lot less
Collapse
 
mtrivera profile image
Miguel T Rivera

Thanks! I want to be consistent with the style, but can see benefits of leaner code. Some of the helper methods just return a value:

  this.getUnitIndex = function(input) {
    return input.search(/[a-zA-Z]/);
  }

I'll refactor the code after the user stories are satisfied.