Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • 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
alpox
@alpox
Like using a closure
And also, you have to return the final array from the function in the end which you did not do yet
Victor De Los Santos
@rdelosh
return the array
the final_arr
n1zzy
@n1zzy
yes ofcourse I returned it...
var final_arr = [];
function steamrollArray(arr) {
    arr.some(function(el) {
        if (Array.isArray(el)) {
            steamrollArray(el);
        } else {
            final_arr.push(el);
        }
    });
    return final_arr;
}
the one with console.log is for my editor so I can see the results
@sjames1958gm hey James do you have any idea what I might be doing wrong here?
Stephen James
@sjames1958gm
@n1zzy For FCC challenges, you cannot use global values, because they are not reset between each function
@n1zzy Looks like someone has mentioned that above
Victor De Los Santos
@rdelosh
might need to do something like
function(){
}
function closure(){
var final_arr = []
function steamrollarray(){
}
}
Stephen James
@sjames1958gm
@n1zzy With recursion you need to collect the values on the return path.
final_array.push(steamRollArray(el))
Moving final_array local
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
Ken Haduch
@khaduch
@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
Ken Haduch
@khaduch
@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:
:star2: 3874 | @khaduch |http://www.freecodecamp.org/khaduch
mstellaluna
@mstellaluna
I was out of ideas tbh
n1zzy
@n1zzy

can someone please explain why

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.