Good code should be semantic, that is, the code should communicate the underlying logic, intention, or meaning of the operation being performed. map() returns an array, forEach() just iterates over an array and does something.
So broadly speaking, when you want to get a new array as a mutation or transformation of an existing one, map should be used. When instead you just want some sort of side effect (e.g. for each element print it, or add a div tag somewhere), then you use forEach.
I'm short, map tells me, "for each element, give me something". forEach tells me, "for each element, do something".
The trick with code transcriptions is to look at how the characters line up with each other; since they're nearly always in monospace fonts, you can compare alignments to the image to make sure you get it right.
50
u/OriginalTyphus Aug 15 '21
Did this came out of an obfuscator?
65
u/dmyl Aug 15 '21
the real 'badcode' part is using a foreach to push elements outside
3
u/R3D3-1 Aug 16 '21
Why
and not just
?
6
u/DaMastaCoda Aug 15 '21
Why not
const _ = Object.values(_data).find(value => value.id+"" == country+"")10
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 15 '21 edited Aug 16 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
8
u/SarahSplatz Aug 16 '21
back in my highschool java class, me and my friend would always name our variables
int thing;string thingthing;bool thing2;float thingthingthing;7
u/KaznovX Aug 15 '21
EHE TE NANDAYO!?
2
u/twoPoundsOfGoldfish Aug 15 '21
oh dear lord
2
u/[deleted] Aug 15 '21
Excuse me sir... What the fuck is going on?
2
u/AhiyaHiya Aug 15 '21
Lol. That's all I have to say.
1
u/CSsharpGO evil Aug 15 '21
Are you… discarding them?
1
u/MisterPyromaniac shameless Aug 15 '21
Oh my God.
1
u/einklee Aug 15 '21
who has the longest?
1
u/PinkPoppies4171 Aug 15 '21
This seriously disturbs me. I feel the need for an exorcism.
1
u/Navanax85 Aug 16 '21
Sweet, programming MadLibs!
1
u/Flyspeck101 Now where's that function declaration Aug 16 '21 edited Aug 16 '21
I use empty characters as folder names.
1
u/Eoussama Aug 16 '21
Object keys should have also been underscorred