Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    The PHP version is quite lame in its checking of "count" use.

    It literally regexes "/count/i" so my intermediate $count variable was erroneously flagged as hacking.

    I just renamed it to $c and it worked.

  • Custom User Avatar

    Great investigation @trashy_incel.

    Indeed my beef was, among other things, that it was expecting stuff like "123abc" to pass.

  • Custom User Avatar

    The PHP version is impossible to pass, all the previous solutions don't work either.

  • Custom User Avatar

    Nah, it's poorly written.

    There are no tricks, everything you need to do is literally written in the description: find the score for each person (gives you the formula) and sort the players by their score (or alphabet).

    But it is absolutely written in a poorly convoluted way.

  • Custom User Avatar

    Something's wrong with php.

    Even solutions that should've been valid do not really work.

    I can't get a fresh one to work either.

    https://www.codewars.com/kata/reviews/5dea647d77902f0001e96d92/groups/5debd0568841740001276d82

  • Custom User Avatar

    Very poorly described, very few test examples, not a great kata at all.

  • Custom User Avatar

    I see, that's a good point then, if everybody calls them closures it's important to stick to them so everybody uses a common language.

    That being said, I feel this is a limit on php part, being an implementation-derived rathen than spec-derived language (such as C, JS, Java and others) terminology is often used in a confusing and improper way.

    That was a helpful discussion in any case for those that will read comments.

  • Custom User Avatar

    No, you can't, you also can't write a PHP anonymous function for which is_object yields false too, but that's beside the point, you wouldn't use the term object interchangeably with the function one.

    Closure, capitalized, refers to a type/class of all anonymous functions, but that is just a name.

    When you use the term closure, not capitalized, you refer to the pair of (function, lexical scope), and PHP anonymous functions do not form closure by default, that's true in every language out there.

    The fact that PHP devs, made the class Closure a parent of all anonymous functions does not imply that all anonymous functions display closure behavior.

  • Custom User Avatar

    Remembering the semicolons after the anonymous functions was the hardest part lol.

  • Custom User Avatar

    I think the text in this paragraph is incorrect if not quite misleading. Closures are a specific subset of anonymous functions, not every anonymous functions forms a closure.

    "An anonymous function is basically an unnamed function (aka closure)"

    First of all, what's a closure?

    A closure is the combination of a function and its lexical scope. In layman terms a closure can access variables in its lexical scope even after the scope has exited.

    In JavaScript the capture of outer variables is automatic, a JS function can always access variables in its outer scope. In PHP it cannot, you need to explicitly use the use keyword.

    There's also other differences in syntax and mutability, but that's irrelevant.

    In PHP, a closure is thus a type of anonymous function that captures variables from the surrounding scope via use.

    Thus, closures are a subset of anonymous function, they are absolutely not synonyms.

  • Custom User Avatar

    Nice one, I really like your solution. Kudos!

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Why would this be more efficient?