## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• Aug 17 09:32
• Jun 20 21:19
@bjorno43 banned @shenerd140
• Apr 25 17:13
@mstellaluna banned @cmal
• Jan 08 22:05
@mstellaluna banned @dertiuss323
• Nov 07 2018 04:42
User @texas2010 unbanned @ows-ali
• Nov 02 2018 16:25
@texas2010 banned @ows-ali
• Oct 12 2018 05:50
@bjorno43 banned @NACH74
• Oct 05 2018 23:02
@mstellaluna banned @JomoPipi
• Sep 16 2018 12:21
@bjorno43 banned @yash-kedia
• Sep 16 2018 12:16
@bjorno43 banned @vnikifirov
• Sep 05 2018 08:12
User @bjorno43 unbanned @androuino
• Sep 05 2018 07:38
@bjorno43 banned @androuino
• Aug 23 2018 16:57
User @bjorno43 unbanned @rahuldkjain
• Aug 23 2018 16:23
@bjorno43 banned @rahuldkjain
• Jul 29 2018 14:13
User @bjorno43 unbanned @jkyereh
• Jul 29 2018 01:00
@bjorno43 banned @jkyereh
• Jul 10 2018 22:09
@bjorno43 banned @manafn
• Jul 06 2018 15:20
@texas2010 banned @imlegend19
• Jul 03 2018 12:28
@bjorno43 banned @vbvmatta
• Jun 29 2018 13:54
@bjorno43 banned @OGTechnoBoy
Markus Kiili
@Masd925
@n1zzy If you use .some(), you can do it without recursion (concat arr elements as long as there are elements that are arrays).
n1zzy
@n1zzy
@sjames1958gm now I get TypeError: arr.some is not a function
@Masd925 I'll try it though I thought recursion would be the easiest way
Markus Kiili
@Masd925
@n1zzy It is.
Stephen James
@sjames1958gm
@n1zzy What is the input that gives that error?
n1zzy
@n1zzy
@sjames1958gm
function steamrollArray(arr) {
var final_arr = [];
arr.some(function(el) {
if (Array.isArray(el)) {
steamrollArray(el);
} else {
final_arr.push(steamrollArray(el));
}
});
console.log(final_arr);
}

steamrollArray([1, [2], [3, [[4]]]]); //[1, 2, 3, 4].
Stephen James
@sjames1958gm
@n1zzy No you should have changed the if part not the else part
Markus Kiili
@Masd925
@n1zzy A good way to structure a recursive solution is to start by checking if arr is an array. That way you can steamrollArray all the array elements.
That is not how you should use .some().
If you just make side effects, use .forEach().
Stephen James
@sjames1958gm
        if (Array.isArray(el)) {
final_array.push(steamrollArray(el));
} else {
final_arr.push(el);
}
n1zzy
@n1zzy
@sjames1958gm now this one logs undefined values
hold on give me a sec... I'll try to re-write the code without recursion
Stephen James
@sjames1958gm
@n1zzy You aren't returning final_arr in the function
My bad, don't push the results of steamrollArray, that just re-creates the array.
You need to concat the result onto final_arr
final_arr = final_arr.concat(steamrollArray(el));
n1zzy
@n1zzy
@sjames1958gm yep that worked!
Stephen James
@sjames1958gm
@n1zzy Generally for recursion you resolve the answer on the return path, rather than with globals
n1zzy
@n1zzy
@sjames1958gm now I understand, this kinda confused me since declaring that variable locally seemed like a bad idea, but I didn't knew that FCC denied global variables
I think I tried once creating a separate function
Stephen James
@sjames1958gm
@n1zzy The issue is that the globals don't get reset between each test
alpox
@alpox
@n1zzy It does not deny them, its just the way global variables work which doesn't work with FCC
@n1zzy If you try multiple functioncalls with the global variable version, you will also see that only the first call works
n1zzy
@n1zzy
aha now I understand
mstellaluna
@mstellaluna
is anyone online?
mstellaluna
@mstellaluna
I have to step away but need some help. I created a background linear-gradient generator and I can't get the values from my dropdown to be applied to the CSS. Not sure what I'm not seeing here. The pen is at https://codepen.io/mstellaluna/pen/pLmjjz
@mstellaluna - did you get it to work since the time you posted your question? It looks like it will set the colors if I select new colors, but not initially with the default colors that you set. But selecting a new color does work. I guess I should say that I'm using the Opera browser on Windows 10.
mstellaluna
@mstellaluna
@khaduch no i cant get it to go in the direction i select
If i check my DOM variables indiviually its fine
@mstellaluna - oh, I just figured that you were in the process and didn't do that. Just add a line similar to this in your setGradient function:
option = direction.options[direction.selectedIndex].text; to fetch the direction from the dropdown, because you don't have an event listener for that. Or add an event listener to trigger the function, but you still have to get the new value.
With that line to grab the new value before you set the body style, it will use it when a color change is made.
mstellaluna
@mstellaluna
@khaduch let me try that. Ill get back to you on it. Thanks!
CamperBot
@camperbot
mstellaluna sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
mstellaluna
@mstellaluna
I was out of ideas tbh
n1zzy
@n1zzy

truthCheck([{"user": "Tinky-Winky", "sex": "male", "age": 0}, {"user": "Dipsy", "sex": "male", "age": 3}, {"user": "Laa-Laa", "sex": "female", "age": 5}, {"user": "Po", "sex": "female", "age": 4}], "age");

should return false ??!
https://www.freecodecamp.org/challenges/everything-be-true

is it because of the zero? shouldn't a number be negative to be false?
Markus Kiili
@Masd925
@n1zzy Only falsy number is 0.
Well, NaN is falsy also.
n1zzy
@n1zzy
oh ok... makes sense now, was confused 'cuz when I used array.indexOf() would always return -1 when nothing found, but would've made more sense if it returned 0... now I understand why we use array.indexOf() > -1
@n1zzy - but if .indexOf() returned 0 then it would indicate that your value was in the first location in the array. -1 isn't an array location.
n1zzy
@n1zzy
hensn5250
@hensn5250
@n1zzy do you have a codepen?
n1zzy
@n1zzy
yes, why?