MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/qfmx6i/creating_a_new_populated_array_in_js/
r/badcode • u/anonymousmouse2 • Oct 25 '21
13 comments sorted by
23
Object.assign(Number.prototype, { *[Symbol.iterator](a){ for (let i = this;i--;) yield this-i; } }); [...3]; // [1, 2, 3]
28
When you really want to generate a new array
20
If it doesn't fuck up something else, I could see this being usefully sometimes, given that it would be integrated in js and you wouldn't need to modify the prototype yourself.
9
this is incredible
can i feature it with attribution in https://evinsellin.medium.com/chaotic-javascript-patterns-1025a8f077e6??
2 u/legendoffjelda Oct 26 '21 That’s a wonderful article! Thanks for the laughs and horrors! 1 u/[deleted] Oct 28 '21 Feel free to feature mine. ^^https://www.reddit.com/r/badcode/comments/agwowr/writing_functions_with_conditions_without_using/eepnbbi/It's supposed to compare two numbers without an explicit if statement. It also takes advantage of (abuses) iterators.
2
That’s a wonderful article! Thanks for the laughs and horrors!
1
Feel free to feature mine. ^^
https://www.reddit.com/r/badcode/comments/agwowr/writing_functions_with_conditions_without_using/eepnbbi/
It's supposed to compare two numbers without an explicit if statement. It also takes advantage of (abuses) iterators.
8
The worst part is that it doesn't even start from 0
1 u/[deleted] Oct 26 '21 edited Sep 27 '24 desert squash zealous close vanish voiceless rotten humorous squeeze wiseThis post was mass deleted and anonymized with Redact
desert squash zealous close vanish voiceless rotten humorous squeeze wise
This post was mass deleted and anonymized with Redact
4
Does the a do anything?
a
I don't think this is bad code, not idiomatic of JS, but given the problem, is super creative and good code.
I think haskell can do that, so it's pretty good.
Where is the bad code?
-1
What the fucking shit are you raving about?
23
u/anonymousmouse2 Oct 25 '21
28
u/toi80QC Oct 25 '21
When you really want to generate a new array
20
u/[deleted] Oct 25 '21
If it doesn't fuck up something else, I could see this being usefully sometimes, given that it would be integrated in js and you wouldn't need to modify the prototype yourself.
9
u/Segfault_Inside Oct 26 '21
this is incredible
can i feature it with attribution in https://evinsellin.medium.com/chaotic-javascript-patterns-1025a8f077e6??
8
u/gipp Oct 26 '21
The worst part is that it doesn't even start from 0
4
u/clemesislife Oct 25 '21
Does the
ado anything?2
u/Raxor53 Oct 26 '21
I don't think this is bad code, not idiomatic of JS, but given the problem, is super creative and good code.
2
u/TigreDeLosLlanos Oct 26 '21
I think haskell can do that, so it's pretty good.
1
u/Respawned234 Oct 26 '21
Where is the bad code?
-1
u/BongarooBizkistico Oct 26 '21
What the fucking shit are you raving about?