[JAVASCRIPT] Code not returning sub-array in array [CLOSED] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

[JAVASCRIPT] Code not returning sub-array in array [CLOSED]

I've been coding this on CodePen and it should return [[value], [value], [etc],[etc]] but it returns just an array. Am I doing something wrong, or it's just our play ground? https://code.sololearn.com/W1H66yIbxZ0z/#js

18th Sep 2017, 7:09 PM
Kustaa
7 Answers
+ 7
actually it works xD use JSON.stringify alert(JSON.stringify(end)); when you simply print the array it is printed spreaded stringify will convert it to a string and display it as it really is you can also print its length and see that the element count has changed
18th Sep 2017, 6:48 PM
Burey
Burey - avatar
+ 7
also you can add the following check if(arr.length%size!==0){ return; } to prevent results with the last subarray on a different size than you expect
18th Sep 2017, 7:07 PM
Burey
Burey - avatar
+ 6
not sure why something with yhe way SL playground compiler works i guess
18th Sep 2017, 7:04 PM
Burey
Burey - avatar
+ 6
np 😉
18th Sep 2017, 7:09 PM
Burey
Burey - avatar
+ 3
wow. ok. Thank you, Burey. CodePen shows me the subarray directly because it has json embedded?
18th Sep 2017, 6:56 PM
Kustaa
+ 3
Thank you very much. Really appreciated.
18th Sep 2017, 7:08 PM
Kustaa
- 1
those challenges were good for practice, I've solved that as https://code.sololearn.com/WWMpp3f98h7g/?ref=app and recently finished the three series, basic intermediate and advanced, algorithms, good practice
18th Sep 2017, 11:32 PM
ysraelcon
ysraelcon - avatar