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
Daniel Simeonov
@dbsimeonov
Home.. in few hours going on holiday finally :sparkles: well deserved rest
n1zzy
@n1zzy
nice! good for you Daniel! looks like this friday the 13th is going to bring you luck!
Daniel Simeonov
@dbsimeonov
I've decided after the short break I will start the job hunting, so have couple of weeks to rest and after that the serious struggle will start :D
paulsda
@paulsda
Good morning guys
Markus Kiili
@Masd925
@paulsda Morning.
paulsda
@paulsda
What’s everybody doing today?
Fabien SHAN
@X140hu4
Reading :D
Markus Kiili
@Masd925
@paulsda Learning Clojure.
Daniel Simeonov
@dbsimeonov
still trying to decide coffee vs tea :D
paulsda
@paulsda
What are you reading Fabien?
Fabien SHAN
@X140hu4
paulsda
@paulsda
Bookmarked, thanks!
Victor De Los Santos
@rdelosh
hello night owls
Stephen James
@sjames1958gm
@rdelosh Morning :)
n1zzy
@n1zzy
var final_arr = [];
function steamrollArray(arr) {
    arr.some(function(el) {
        if (Array.isArray(el)) {
            steamrollArray(el);
        } else {
            final_arr.push(el);
        }
    });
    console.log(final_arr);
}
am I missing something?
when I run this locally it works
but in FCC it doesn't pass
eeflores
@eeflores
make final_arr local to function
alpox
@alpox
@n1zzy Don't use global variables. That messes things up
eeflores
@eeflores
should the function return the array?
n1zzy
@n1zzy
yes
making the variable local messes up the code...
'cuz if you look at it its recursive
alpox
@alpox
@n1zzy So you have to find another solution.
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