Hacker News new | past | comments | ask | show | jobs | submit login

Shouldn't the uppercase of a number be a string?

    const makeUpperCase = t.pattern(
      (input: string) => input.toUpperCase(),
      (input: number) => '' + input
    );
Otherwise you get odd behaviours like:

    makeUpperCase('1') + makeUpperCase('1') = '11' (probably what you want)
    makeUpperCase(1) + makeUpperCase(1) = 2 (probably not what you want)



...wait. Why would the uppercase of '1' be '11'? It would just be '1'.


I had to reread it a few times to parse it. Its result of "adding" the uppercase of 1 that should be 11, not the uppercase itself.

In other words, the result of "makeUppercase" should be a string, not a number.


I see it now.


Yeah probably, but it's just an example




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: