Skip to content

More low-hanging transformations #794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jvoisin opened this issue Jan 20, 2025 · 6 comments
Open

More low-hanging transformations #794

jvoisin opened this issue Jan 20, 2025 · 6 comments

Comments

@jvoisin
Copy link

jvoisin commented Jan 20, 2025

Maths

  • Number(s)+[s] +s
  • n=n-1n--
  • n=n+1n++
  • all the n = n ° mn°=m family, with ° being +, -, /, * and %
  • ParseFloat(n)+n
  • x!=yx^y if x and y are integers
  • -10~9, -100~99, … and so on :D
  • N00…0 with N an integer → Ne00…0

Arrays

  • a.concat()[...a]
  • x[x.length-N]x.at(N)

Random

  • Math.random()<0.5new Date&1, as Date returns a number of ms, albeit it might be problematic if called in a super-tight loop.
  • Math.floor(Math.random()*N))new Date%N

Misc

  • while(1)for(;;)
@tdewolff
Copy link
Owner

Thanks Voisin. What's the difference between +[s] and +s?

@jvoisin
Copy link
Author

jvoisin commented Jan 20, 2025

Oops, it's a typo, +s should be enough for Number

@tdewolff
Copy link
Owner

The Random ones are not feasible. Math.random is not the same as new Date, the former is probably a much more secure random source, while the latter is a poor man's random source. I believe we already do the while(1) => for(;;) one.

The parseInt and parseFloat conversions are actually not such a good idea. Try inputting something invalid and the output is different between the two.

@jvoisin
Copy link
Author

jvoisin commented Jan 21, 2025

> parseFloat("aaa")
NaN
> +"aaa"
NaN 

looks identical do me.

@tdewolff
Copy link
Owner

tdewolff commented Jan 21, 2025 via email

@jvoisin
Copy link
Author

jvoisin commented Jan 21, 2025

> +"5a"
NaN
> parseInt("5a")
5
> parseFloat("5a")
5 

Damn :<

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants