## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
• Create your own community
##### Activity
kevincauto
@kevincauto
That's awesome! I just learned something new.
David Castner
@davidjcastner
used a ton of console.log()'s to find it
kevincauto
@kevincauto
Ok so I know that i=-1 was a clunky solution. I just moved the if statement case for empty arrays out of the loop and set the for loop to var i=0 again. It still works.
David Castner
@davidjcastner
Nice exactly what I was going to suggest
kevincauto
@kevincauto
Thank you so much @davidjcastner! That challenge was driving me crazy.
Thanks @Lilyheart for taking a look at it as well!
Lily Romano
@Lilyheart
Man, I gotta get back to FCC soon or both ya’ll gonna pass me!
David Castner
@davidjcastner
Here is what I had typed up for suggestions on how to make your code clearer
function steamrollArray(arr) {
var answer = [];
// steamrollArray2 is redundant
// here's how to avoid writing the code twice:
//
// instead we can define a function instead here rather than the global
// namespace and then it avoids writing the same code twice
//
// notice it's doesn't take the answer as an argument
// that's because it will have access to it since it's being defined inside
// the steamrollArray function
var recursiveSteamrollArray = function(arr) {
// starting at index of -1 makes your code unclear, and therefore is
// a bad practice, even though your logic is correct
//
// to avoid the case of arr.length being 0 we can check before enterting
// the for loop
if (arr.length === 0) {
}
for (var i = 0; i < arr.length; i++) {
// no need to use if (i === -1) { i++; } anymore
//if the current array index does
//not contain another array
if (!Array.isArray(arr[i])) {
}
//if the current array has a
//sub-array use recursion
if (Array.isArray(arr[i])) {
}
}
};
// recursiveSteamrollArray was defined but not called yet
// so let's call the function and then return answer
recursiveSteamrollArray(arr);
}

console.log(steamrollArray([1, [2],
[3, [
[4]
]]
]));
kevincauto
@kevincauto
Ok cool. I will look this over now.
David Castner
@davidjcastner
@kevincauto it's basically a way to avoid having to duplicate your code in the fcc environment
kevincauto
@kevincauto
@davidjcastner Love it. Yeah that all makes sense. Everything is contained within the function and avoids the global namespace entirely.
Lily Romano
@Lilyheart
Oh that is an interesting way to solve!
David Castner
@davidjcastner
I'm having lunch right now, but you can simplify that even more by using Array.map I'll post that after I eat
Lily Romano
@Lilyheart
Here is how I did it. I am bad at commenting sometimes
function steamrollArray(arr) {
var flatArr = [];
for (var i = 0; i < arr.length; i++) {
if (Array.isArray(arr[i])) {
var tempArr = steamrollArray(arr[i]);
for (var j = 0; j < tempArr.length; j++) {
flatArr.push(tempArr[j]);
}
} else {
flatArr.push(arr[i]);
}
}

return flatArr;
}
kevincauto
@kevincauto
Nice!
David Castner
@davidjcastner
// here is how to do it with Array.map
function steamrollArray(arr) {
var answer = [];
var flatten = function(element) {
if (Array.isArray(element)) {
element.map(flatten);
} else {
}
};
flatten(arr);
}
Mike
@dcpking
Slowly working through the BootCamp (for my sins!). Inputs of type date and password are new to me, and placeholders, and also the checking in the button on the form to see if you entered valid dates, etc. I used to have to write JavaScript to validate those!!
Jonathan Herman
@lantech19446
If i learn anything from @davidjcastner it damn well better be commenting my code lol.
Mike
@dcpking
@lantech19446 You're not writing in C now, Jonathan (C == "Write-Only Code")
David Castner
@davidjcastner
@lantech19446 I appreciate the compliment, since if there's anything that I teach to people writing code, it would how to write clean & clear code
Robert Maylie
@rmaylie9560
I definitely wouldn't of thought of writing that method recusively. Although I do try to keep variable scope as small as possible.
Lily Romano
@Lilyheart
Whenever you don't know how deep you will need to go, it is pretty much needed.
Robert Maylie
@rmaylie9560
Can you explain?
Lily Romano
@Lilyheart
Sure! In steamroll, if you didn't have the test cases, you'd have no idea how far deep the arrays go. Maybe 2, Maybe 12. Like in factorial, you may only be doing ^6 or ^106. When writing the code, you don't know how deep you will need to go. Factorial you could for loop, but in steamroll not so much as in factorial you know from the onset how many. But in steamroll, until the code fully dissects the array, you'd never know how many dimensions the array has.
Hopefully that makes sense. Sleep was not so grand.
Robert Maylie
@rmaylie9560
Perfect sense, thank you.
Lily Romano
@Lilyheart
This won't stay running forever, but here is where I'm at in Colt Steele's bootcamp. Registration works (have to register before adding campgrounds or comments). Registration was just added so some things still need tweaking (e.g. author on comment add form). Other things don't work yet and just have placeholders, so no fussin' about that :p Overall really enjoying this. https://colt-steele-bootcamp-lilyheart.c9users.io/campgrounds
David Castner
@davidjcastner
@Lilyheart what are you using for user accounts? I'm curious
Lily Romano
@Lilyheart
You can see ALL the code in the github [Yes, I know even secrets are listed, I'm not really worried about it for this application... and regardless of that, the secret that is pushed isn't the same as the live one anyway :p )
can you create a user and poke around if you wish
David Castner
@davidjcastner
nice, I'll have to look into it
Lily Romano
@Lilyheart
When someone's Facebook account is 5 hours old, I am hesitant to approve...
David Castner
@davidjcastner
Lily Romano
@Lilyheart
@davidjcastner earlier today. I PMd you a link as I don't wanna call anyone out publicly.
Robert Maylie
@rmaylie9560
Note to self: pickles eventually go bad. Fight the temptation.
-that is all.
Lily Romano
@Lilyheart
did they join a pickle gang?
Robert Maylie
@rmaylie9560
They did! nothing worse than a pack of unruley pickled cucumbers causing trouble in the fridge.
Jonathan Herman
@lantech19446
Pickles only go bad if they aren't fully submerged in brine otherwise it's impossible for the bacterium necessary to spoil them to exist. L. Bacillus bacteria are anaerobic the others aren't.
Lily Romano
@Lilyheart
After a long while, the pickles, even fully submerged, can become… un-tasty. Submerging them will ensure they “live” as long as possible tho!
Jonathan Herman
@lantech19446
Possibly untasty because the salt in the brine may eventually become fully absorbed into the cucumber it just wont spoil lol. All this is making
Me want to start a batch of kraut thoug
Lily Romano
@Lilyheart
... Now I want pickles... I wonder if mine have gone bad. I bought them so long ago.
Jonathan Herman
@lantech19446
why do you buy them when cucumbers are so cheap?
Lily Romano
@Lilyheart
Because I have a skin condition where I avoid water whenever possible.
Making things is problematic.
Jonathan Herman
@lantech19446
does vinegar effect you too or just the water?
Lily Romano
@Lilyheart
vinegar on my hands would need to be washed off.