r/ProgrammerDadJokes • u/neelsg • Jan 08 '18
#1 DAD ['S','u','n','s','h','i','n','e']
Array of sunshine
36
19
u/TominatorBE Jan 08 '18
In some languages a string can already be used as an array
40
17
u/fahrenheitrkg Jan 08 '18
char cStr[9];
cStr[0] ='S';
cStr[1] ='u';
cStr[2] ='n';
cStr[3] ='s';
cStr[4] ='h';
cStr[5] ='i';
cStr[6] ='n';
cStr[7] ='e';
cStr[8] ='\0';8
u/Periapsis_ Jan 09 '18
letters="sunhie"word=(0,1,2,0,3,4,2,5) for i in word: print(letters[i],end="")
-6
Jan 08 '18
//get those magic numbers out of here!
var str = 'sunshine';
var ch_array = [];
for(var str_itor = 0; str_itor < str.length; str_itor++){
ch_array.push(str[str_itor]);}
6
u/Metallkiller Jan 08 '18
How is sunshine a single character?
Also
char* str = "Sunshine";12
Jan 08 '18
Sorry JavaScript. Single and Double Quotes are treated the same.
5
1
u/KJ6BWB Jan 09 '18
Just another reason to always use double quotes there, so that there's less confusion when you go to another language. Just because a language lets you do something didn't mean you have to do it.
1
u/aarondburk Jan 29 '18
Just because a language makes you incessantly hit the shift key, doesn’t mean you have to do it in all the languages.
1
-8
1
1
243
u/AskMeIfImAReptiloid Jan 08 '18
["Hip", "Hip"]
Hip, Hip array