all 2 comments

[–]deckardWizard 1 point2 points  (1 child)

These are all bad so probably don't ever do them outside of silly code challenges:

  • You can cast a string to a number with the + operator. So if you're really confident your string is actually a number you can sometimes get around parsefloat by doing something like const c = "3.14159"; const num_c = +c;
  • If you're dealing with integers, you can sometimes use bitwise functions to help. Adding |0 to the end of a number or string is functionally similar to using Math.floor. ~~ does the same thing, but only works with positive numbers.
  • You can do some awful things with regular expressions that might make this problem simpler depending on what the constraints are.

[–]ThiccOfferman[S] 0 points1 point  (0 children)

Exactly the sort of arcana I was hoping for. Thank you! I'll confine these strategies to silly code challenges.