+ 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
7 Respuestas
+ 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
+ 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
+ 6
not sure why
something with yhe way SL playground compiler works i guess
+ 6
np 😉
+ 3
wow. ok. Thank you, Burey. CodePen shows me the subarray directly because it has json embedded?
+ 3
Thank you very much. Really appreciated.
- 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