Ad
  • Custom User Avatar

    I think the comments was to discuss the actual kata and not made up requirements, but I'll offer my two cents.

    I'm not sure if your underlying suggestion is to use JS Intl limited features to pluralize/translate the units, but internacionalization/localization is not trivial and the proper way to go is to use a library for it. Even for a simple kata like this we would need the following features:

    • Word translations (not just the time units, also the "and" + "now")
    • Handle whitespace (not all languages use it)
    • Pluralization
    • Handle enum separator (not all languages use a comma)
    • Handle the formatting of the number (not all languages use arabic numbers for time, but even then we would likely need separators for values >= 1000)

    So it's not like I would need to reimplement a one-line function if I wanted to localize to, let's say, Japanese. I would probably need to scrap that function altogether and use a completely different approach.

    My take when approaching these katas is to use code that is readable and extensible. And stick to the most simple solution posible. A readable one-liner is not a bad take here IMO

  • Default User Avatar

    Works as requested. But note that this would not work for languages other than english, because then it is not about adding a "s" to make the plural. So making it able to work with italin, spanish or other languages would make necessary to reimplement the formatUnit.

  • Custom User Avatar

    Thanks! Short? yes. Brilliant? ¯\_ (ツ) _/¯

  • Default User Avatar

    I don't get something. Can somebody explain me why "if (maxWithDigits(i) === mx)"? By doing this you are searching for the max number, but actually what we want is to find the first number (minimum), higher than n, using the given digits.

  • Default User Avatar
  • Default User Avatar

    One of the nicest solutions, IMHO

  • Default User Avatar
  • Default User Avatar

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