Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more
  • 351434c9d805123a6a2992116aa1c30d?d=https%3a%2f%2fidenticons.github.com%2f1b0ce67d6184c5169c763503388a7724

    I have basically no background in algorythm efficiency analysis so I don't focus on it ever so thank you for the explanation and suggestion; I would implement your solution using a .reduce() but it would equate to the same thing.

    I imagine that there are more difficult kata where efficiency of the solution plays a part in success or not and I actually avoid those as it isn't something that I have ever needed to take into account.

  • 9130211?v=3

    If you were to use Array.sort(), first create a new array by doing array.slice(0), which will create a shallow copy of the input array. Then it can be sorted without mutating the input.

    However, just using a simple for loop allows you to complete this Kata in O(n) instead of O(n log(n)); Using sort means that for large arrays you're going to see a huge performance disadvantage versus just finding the max and second max using a for loop.

  • 351434c9d805123a6a2992116aa1c30d?d=https%3a%2f%2fidenticons.github.com%2f1b0ce67d6184c5169c763503388a7724

    Thanks for the comment. What solution suggestion do you have?

  • 9130211?v=3

    Any solution using sort isn't best practice, as it's possible to complete this Kata in one iteration over the input array instead of spending time to sort it.

    (not to mention, this mutates the input array as well!)

  • Assets.github.com%2fimages%2fgravatars%2fgravatar-user-420

    Works for different board sizes. Also shorts properly when a rowWin is found. Can be improved to also short when other wins are found.