2
\$\begingroup\$

So the kata/problem was: "Simple, given a string of words, return the length of the shortest word(s)."

Example test: findShort("Bitcoin will maybe save the world")

And my solution was:

 function findShort(s){
    //   convert string to array
      const strArr = s.split(' ');
    //   loop through array and find length
      const lengthOfWords = strArr.map(string => {
        return (string.length);
      })
    //   output length of shortest string
      return Math.min(...lengthOfWords);
    
    }
\$\endgroup\$
2
  • 4
    \$\begingroup\$ The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly. \$\endgroup\$
    – Mast
    Oct 27 at 18:39
  • 2
    \$\begingroup\$ There are some edge cases you may want to consider: Will input always contain at least 1 word? Will input only contains letters and spaces, will there be any hyphen or punctuation marks? And what does a "word" mean in the question? What about input contains 2 continuing spaces? \$\endgroup\$
    – tsh
    Oct 28 at 8:58
2
\$\begingroup\$

As far as implementation goes, it looks generally good to me (though arguably you should be splitting on any whitespace character, not just spaces). However I do feel that the function name (findShort) is unclear, and additionally those comments do not offer any benefit. Indeed, the second one is perhaps even misleading.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.