this post was submitted on 14 Apr 2024
0 points (NaN% liked)

linuxmemes

20870 readers
1980 users here now

I use Arch btw


Sister communities:

Community rules

  1. Follow the site-wide rules and code of conduct
  2. Be civil
  3. Post Linux-related content
  4. No recent reposts

Please report posts and comments that break these rules!

founded 1 year ago
MODERATORS
 
top 5 comments
sorted by: hot top controversial new old
[–] Naich@lemmings.world 0 points 5 months ago (1 children)

Want to print out all odd numbers from 1 to 100? Easy:

for(_=[];_<+!![]+""+[]*[]+[]*[];_++)(_%+(!![]+!![])?console.log(_):[]);

[–] Naich@lemmings.world 0 points 5 months ago (1 children)

Actually, I prefer this one: for(_=[];_<+!![]+""+[]*[]+[]*[];_++%+(!![]+!![])?[]:console.log(_));

[–] Naich@lemmings.world 0 points 5 months ago (1 children)

Or this one without the "undefined" when run in a browser console:

for(_=[];_<+!![]+""+[]*[]+[]*[]-!![]-!![];_++%+(!![]+!![])?[]:console.log(_));_+!![]

[–] boredsquirrel@slrpnk.net 1 points 5 months ago (1 children)

Wtf people, can somebody explain?

[–] Naich@lemmings.world 1 points 5 months ago

_ is a variable name, [] becomes 0 when converted to an integer, !![] becomes 1. The + "" + means that the integers 1, 0, 0 get converted to a string - "100", which gets converted back to an integer because it's in the for loop. And there's various other horrible conversions going on to make it all work.