These are chat archives for FreeCodeCamp/HelpFrontEnd

29th
Sep 2017
you tried it!
@you-tried-it
Sep 29 2017 00:50
um...
thanks
hmm?
G-4-R-Y
@G-4-R-Y
Sep 29 2017 01:26
$('#submit').on('click', function() {
  var search = document.getElementById('input').value;
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "https://en.wikipedia.org/w/api.php?action=opensearch&search=" + search + "&format=jsonfm", true);
  xhr.send(null);
  console.log(search);

  xhr.onload = function() {
    console.log(search);
    responseObject = JSON.parse(xhr.responseObject);
    var linkList = "";
    console.log(responseObject);
hey guys, can anyone help me? The first console log is working just fine, although the second one isn't working. Why does the second function don't work?
piteto
@piteto
Sep 29 2017 01:38
@G-4-R-Y A few issues:
  • cross domain security restrictions require us to add &origin=* to the URL when using the wikipedia API
  • you want format=json not jsonfm
  • get the responseText not the responseObject
G-4-R-Y
@G-4-R-Y
Sep 29 2017 01:40
@piteto does I always have to use responseText?
or the response's name is different for each api?
piteto
@piteto
Sep 29 2017 01:41
@G-4-R-Y I've never retrieved the responseObject back, but I'm sure there are scenarios where you can use it
If you're okay supporting modern browsers, by the way, it's much easier to use fetch() compared to XMLHttpRequest()
G-4-R-Y
@G-4-R-Y
Sep 29 2017 01:42
Oh, i'll surely read about it! I was following a book here and it only talks about XMLHttpRequest()
@piteto thank you very much!!
CamperBot
@camperbot
Sep 29 2017 01:42
g-4-r-y sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
:cookie: 164 | @piteto |http://www.freecodecamp.com/piteto
Gersho
@Gersho
Sep 29 2017 01:43
i'd say you should try a few different methods since there's multiple opportunities (getjson, fetch, xmlhttprequest,...)
piteto
@piteto
Sep 29 2017 01:44
XMLHttpRequest is the classic way to do it, for sure, and will work in any browser. It's just a lot of code :)
Gersho
@Gersho
Sep 29 2017 01:44
i was thinking about being able to read it at least
like in other people code
but yeah it's a lot of code, i have about 40 lines for 2 calls
piteto
@piteto
Sep 29 2017 01:45
This is fetch():
  fetch("https://en.wikipedia.org/w/api.php?action=opensearch&search=" + search + "&format=json&origin=*")
    .then(res => res.json())
    .then(console.log)
but....still people out there running windows xp or whatever and it won't work
you tried it!
@you-tried-it
Sep 29 2017 03:00
um...
anyone code in java?
Bryan Jay B. Panesa
@bryanpanesa
Sep 29 2017 03:04
@korzo @arpitanand112 Thank you so much!
CamperBot
@camperbot
Sep 29 2017 03:04
bryanpanesa sends brownie points to @korzo and @arpitanand112 :sparkles: :thumbsup: :sparkles:
api offline
:cookie: 554 | @korzo |http://www.freecodecamp.com/korzo
Jerzz
@2cool4school
Sep 29 2017 03:06
@NerdyNerves What are the questions?
Jerzz
@2cool4school
Sep 29 2017 03:15
Hola, room. I have a css question if anyone has time? I have two <div class="well"> inside another <div class="well"> and depending on the current content inside the <div>'s their height varies. I want to set their height equal to a certain percentage of the parent <div class="well"> so that their height always remains the same. Does anyone know how to accomplish this?
Long Nguyen
@longnt80
Sep 29 2017 03:18
@2cool4school so what's inside the child div?
content?
Jerzz
@2cool4school
Sep 29 2017 03:20
@longnt80 content
Long Nguyen
@longnt80
Sep 29 2017 03:21
@2cool4school you want the inside divs' height to always be the same?
Jerzz
@2cool4school
Sep 29 2017 03:21
@longnt80 exactly. as in like 90% of the height of the parent <div>
Long Nguyen
@longnt80
Sep 29 2017 03:21
you an use flexbox
by default their height should be the same
Jerzz
@2cool4school
Sep 29 2017 03:22
@longnt80 They are when empty, but one contains content initially and one contains dynamic content.
Camper
@camper-fcc
Sep 29 2017 03:24
@2cool4school Do you have any visual example of what you're trying to accomplish or any code you can share? Does adding height: 90%;to the inner div not work? I agree with @longnt80 about using flexbox though.
Jerzz
@2cool4school
Sep 29 2017 03:25
@camper-fcc No, setting height: 90% doesn't work. although setting the pixels for height does. its curious.
Jerzz
@2cool4school
Sep 29 2017 03:26
@longnt80 good example and advice. thanks!
CamperBot
@camperbot
Sep 29 2017 03:26
2cool4school sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 561 | @longnt80 |http://www.freecodecamp.com/longnt80
Jerzz
@2cool4school
Sep 29 2017 03:27
@camper-fcc thanks for the input
Long Nguyen
@longnt80
Sep 29 2017 03:27
@2cool4school np
Jerzz
@2cool4school
Sep 29 2017 03:27
@camper-fcc it didn't give you brownie points? thanks
CamperBot
@camperbot
Sep 29 2017 03:27
2cool4school sends brownie points to @camper-fcc :sparkles: :thumbsup: :sparkles:
:cookie: 14 | @camper-fcc |http://www.freecodecamp.com/camper-fcc
Camper
@camper-fcc
Sep 29 2017 03:29
@2cool4school No problem. I'm still learning too and seeing @longnt80's solution helps. :)
@2cool4school Are you familiar with flexbox?
Camper
@camper-fcc
Sep 29 2017 03:34
@longnt80 Is the flex: 1 1 auto; code necessary in this example? The default is flex: 0 1 auto;right? Why would this particular solution need flex-grow: 1? Just curious, thanks.
CamperBot
@camperbot
Sep 29 2017 03:34
camper-fcc sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 562 | @longnt80 |http://www.freecodecamp.com/longnt80
piteto
@piteto
Sep 29 2017 04:13

Assuming this HTML:

<div class="container">
  <div class="row well-row">
    <div class="col-xs-6 well">
      <p>blah</p>
    </div>
    <div class="col-xs-6 well">
      <p>blah</p>
      <p>blah</p>
      <p>blah</p>
    </div>
  </div>
</div>

This css is all that's needed:

.well-row {
  display: flex;
}
@camper-fcc
Camper
@camper-fcc
Sep 29 2017 04:20
@piteto Ok, cool, thanks. That's what I'm thinking too. I was curious if @longnt80 had a specific reason for wanting flex-grow: 1; in this case, as it's possibly helpful for other aspects of the project.
CamperBot
@camperbot
Sep 29 2017 04:20
camper-fcc sends brownie points to @piteto and @longnt80 :sparkles: :thumbsup: :sparkles:
api offline
:cookie: 165 | @piteto |http://www.freecodecamp.com/piteto
piteto
@piteto
Sep 29 2017 04:21
I think it's for making the columns equal width @camper-fcc but with bootstrap, the grid system can be used instead
And with Bootstrap 4, no extra CSS is needed at all:
<div class="container">
  <div class="row">
    <div class="col card bg-light">
      <p>blah</p>
    </div>
    <div class="col card bg-light">
      <p>blah</p>
      <p>blah</p>
      <p>blah</p>
    </div>
  </div>
</div>
Peter
@zzt1413
Sep 29 2017 04:24
var sd=$("#send");
sd.click(function(){
var value = $( "#info" ).val();
var tl=$("#textl");
tl.text(value);
tl.animate({
left: "0px"
}, 5000,function(){
tl.empty();
});
});If i want it to go back to the starting point, how do i handle it?
piteto
@piteto
Sep 29 2017 04:27
@zzt1413 Do you want it to animate back to the starting?
If so, call .animate({}) again with the initial left value, otherwise, use .css() inside your animation complete function
https://s.codepen.io/anon/pen/wreaOa?editors=1011
Peter
@zzt1413
Sep 29 2017 04:40
thankyou,I try it
Peter
@zzt1413
Sep 29 2017 04:48
yes,it did,thanks
Richard
@rylew0925
Sep 29 2017 07:30
What is the difference between line-height and leading?
I'm referring to the typography subject
you tried it!
@you-tried-it
Sep 29 2017 09:22
hi! um... yea!
can i...
...ask a simple question?
Fabien SHAN
@X140hu4
Sep 29 2017 09:27
Try
you tried it!
@you-tried-it
Sep 29 2017 09:39
try what?
@X140hu4 what? :confused:
Fabien SHAN
@X140hu4
Sep 29 2017 09:45
try asking your question :)
you tried it!
@you-tried-it
Sep 29 2017 11:44
@X140hu4 ok...
Ian Gracia
@iangracia
Sep 29 2017 12:23
:sparkles:
:shipit:
Ken Haduch
@khaduch
Sep 29 2017 12:38
@rylew0925 - re: :point_up: September 29, 2017 3:30 AM - check this article
Ian Gracia
@iangracia
Sep 29 2017 12:45

function steamrollArray(arr) {
  // I'm a steamroller, baby
  var newArr = [];

  function nestArray(arr) {
   for (var i=0; i<arr.length; i++){    
    if (Array.isArray(arr[i])) {
        nestArray(arr[i]); 
        return "this happend";
    }


        newArr.push(arr[i]);
        return "this happend"; 

   }
  }

  nestArray(arr);

  return newArr;
}

steamrollArray([1, [2], [3, [[4]]]]);
Why is this returning [1] and not "this happend"
Matej Bošnjak
@mbosnjak01
Sep 29 2017 12:51
hmm
you created function inside a function
Ian Gracia
@iangracia
Sep 29 2017 12:53
yes
is that wrong?
Matej Bošnjak
@mbosnjak01
Sep 29 2017 12:53
well, yeah that's not how things are usually done
Ian Gracia
@iangracia
Sep 29 2017 12:54
ok, but do you know the answer to my question?
:worried:
Christian-Peter
@cpheimbach
Sep 29 2017 12:55
hi Ian,
no problem to have functions within functions from a doable point of view. It is nice to stay as flat as possible. But let’s leave that aside for a moment and discuss your actual questions
so you call the steamroll function
then this function invokes the nestArray one
in there you mutate the array newArr and return a string
you then return newArr which was mutated by nestArray().
The “this happend” string is just nowhere picked up
so nestArray returns it but into the void
it would be different if you wrap the invocation of nestArray() into a console.log(nestArray(arr))
now the returned value is picked up by a function that does something with it: logging to the console
Ian Gracia
@iangracia
Sep 29 2017 13:04
i understand now, thank you @cpheimbach
CamperBot
@camperbot
Sep 29 2017 13:04
iangracia sends brownie points to @cpheimbach :sparkles: :thumbsup: :sparkles:
:cookie: 362 | @cpheimbach |http://www.freecodecamp.com/cpheimbach
Ian Gracia
@iangracia
Sep 29 2017 13:34
how can i change the boolean statement in a for loop if the for loop is under a recursion
Christoph Szczechowicz
@christophszcz
Sep 29 2017 13:35
Let's see the code
heroiczero
@heroiczero
Sep 29 2017 13:41
a recursion function triggers the same function. So, you would need another conditional statement to "catch" the function before you trigger the said boolean statement and make it trigger a different one.
Jorge
@OrangeKulture
Sep 29 2017 13:46
whats happening fellow campers :sunny:
heroiczero
@heroiczero
Sep 29 2017 13:51
@OrangeKulture :wave: Hi.
you tried it!
@you-tried-it
Sep 29 2017 13:56
hi :(
Jorge
@OrangeKulture
Sep 29 2017 13:56
hey guys!
you tried it!
@you-tried-it
Sep 29 2017 13:56
does anyone here know how to code in java?
heroiczero
@heroiczero
Sep 29 2017 13:56
@you-tried-it why so sad. lets turn that frown upside Down :)
Jorge
@OrangeKulture
Sep 29 2017 13:57
its cuz @you-tried-it looks like a muppet today :joy:
ive done a little java in the past ..
cant say im advanced level tho
you tried it!
@you-tried-it
Sep 29 2017 13:57
oh... yay!
Jorge
@OrangeKulture
Sep 29 2017 13:58
im fighting with heroku atm .. dam it pisses me off to no end
Tomáš Dvořák
@Deepress
Sep 29 2017 13:58
Anyone used Bootstrap 4 installed through bower and then included by wiredep and compiled with postcss and sass ?
you tried it!
@you-tried-it
Sep 29 2017 13:58
anyone else... :worried:
Jorge
@OrangeKulture
Sep 29 2017 13:59
@you-tried-it what seems to be the bugle
heroiczero
@heroiczero
Sep 29 2017 13:59
@Deepress I use some Bootstrap 4 some of the classes are changed from bootstrap 3 so I still have to get used to it
you tried it!
@you-tried-it
Sep 29 2017 14:00
@OrangeKulture i'm not happy. noone here seems to know how to code in java.
Tomáš Dvořák
@Deepress
Sep 29 2017 14:01
@heroiczero well i have my own scss file in which i have wiredep comments and when i execute "grunt wiredep", the scss file is included BUT when i try to run postcss over the scss file it fails in importing files in bootstrap.scss, because it looks for them in current folder :/
Ian Gracia
@iangracia
Sep 29 2017 14:01
function steamrollArray(arr) {
  // I'm a steamroller, baby
  var newArr = [];

  function nestArray(arr) {
   for (var i=0; i<arr.length[i]; i++){    
    if (Array.isArray(arr[i])) {
        nestArray(arr[i]);         
    } 

        newArr.push(arr[i]);       
   }
  }


  nestArray(arr);
  return newArr;
}

steamrollArray([1, [2], [3, [[4]]]]);
Jorge
@OrangeKulture
Sep 29 2017 14:01
yeah i meant was was the java question you had .. since its a front end channel, and java blows for front end dev (imo) .. then u won't have too much luck here, i reckon @you-tried-it
Ian Gracia
@iangracia
Sep 29 2017 14:01
here you go @christophszcz @heroiczero
you tried it!
@you-tried-it
Sep 29 2017 14:01
@heroiczero I need to learn java so i can impress this cute guy that i like
Ian Gracia
@iangracia
Sep 29 2017 14:01
i have to change arr.length in the for loop to [i] when its in a recursion
you tried it!
@you-tried-it
Sep 29 2017 14:02
@OrangeKulture arrays...
Tomáš Dvořák
@Deepress
Sep 29 2017 14:02
@heroiczero maybe i have the workflow badly designed :/
Jorge
@OrangeKulture
Sep 29 2017 14:02
@you-tried-it try cave of programming .. john makes a decent introduction, altho his tone of voice is the most sleep inducer i've ever know in my life
you tried it!
@you-tried-it
Sep 29 2017 14:03
@OrangeKulture ok... oh boy here we go
@OrangeKulture so where's this... cave of programming?
Jorge
@OrangeKulture
Sep 29 2017 14:04
@you-tried-it it's a website
java introduction is like a million vids long .. very extensive and nice explanation,
its free too
you tried it!
@you-tried-it
Sep 29 2017 14:04
@OrangeKulture do u hv a link?
Jorge
@OrangeKulture
Sep 29 2017 14:05
@iangracia why do u want to recurse? is the test not passsing?
CamperBot
@camperbot
Sep 29 2017 14:05
orangekulture sends brownie points to @iangracia :sparkles: :thumbsup: :sparkles:
:cookie: 336 | @iangracia |http://www.freecodecamp.com/iangracia
Jorge
@OrangeKulture
Sep 29 2017 14:05
what the hell cbot
Ian Gracia
@iangracia
Sep 29 2017 14:05
the above code returns a mess
Moisés Man
@moigithub
Sep 29 2017 14:05
gracias <-- thanks in spanish @OrangeKulture
Jorge
@OrangeKulture
Sep 29 2017 14:05
@you-tried-it caveofprogramming.com
you tried it!
@you-tried-it
Sep 29 2017 14:06
@OrangeKulture :kissing_heart: :wink: :+1:
Jorge
@OrangeKulture
Sep 29 2017 14:06
@iangracia probably because you are using the same variable name for both functions?
CamperBot
@camperbot
Sep 29 2017 14:06
orangekulture sends brownie points to @iangracia :sparkles: :thumbsup: :sparkles:
api offline
Jorge
@OrangeKulture
Sep 29 2017 14:06
lol @ cbot
im not sending brownies as of yet dammit! brownies are still cooling down
Jorge
@OrangeKulture
Sep 29 2017 14:07
@you-tried-it learn Angular and impress another guy, thats my advice :joy:
you tried it!
@you-tried-it
Sep 29 2017 14:08
@OrangeKulture another guy? but i want this one :worried:
@heroiczero oh and thnx Jorge :kiss:
CamperBot
@camperbot
Sep 29 2017 14:08
you-tried-it sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1791 | @heroiczero |http://www.freecodecamp.com/heroiczero
heroiczero
@heroiczero
Sep 29 2017 14:08
@iangracia you know if Array.isArray it will just keep on executing nestArray and you will never get out of the cycle
CamperBot
@camperbot
Sep 29 2017 14:08
heroiczero sends brownie points to @iangracia :sparkles: :thumbsup: :sparkles:
:cookie: 337 | @iangracia |http://www.freecodecamp.com/iangracia
Jorge
@OrangeKulture
Sep 29 2017 14:08
@iangracia also, when you check to see if Array.isArray, u want to inclc='ude an else statement
you tried it!
@you-tried-it
Sep 29 2017 14:09
@OrangeKulture why angular anyway?
Jorge
@OrangeKulture
Sep 29 2017 14:09
*include an esle statement, else ... what @heroiczero said
@you-tried-it or React .. it's def better for you if you are trying to get into Web Dev
you tried it!
@you-tried-it
Sep 29 2017 14:10
@OrangeKulture what's react?
Jorge
@OrangeKulture
Sep 29 2017 14:10
Javascript library .. front end rendering and virtual DOM .. pretty cool
Ian Gracia
@iangracia
Sep 29 2017 14:10
i have an else statement, its push
Jorge
@OrangeKulture
Sep 29 2017 14:10
@iangracia no u dont
CamperBot
@camperbot
Sep 29 2017 14:10
orangekulture sends brownie points to @iangracia :sparkles: :thumbsup: :sparkles:
api offline
Jorge
@OrangeKulture
Sep 29 2017 14:10
at least with the code you showed us
Ian Gracia
@iangracia
Sep 29 2017 14:10
if array[i] is not an array it pushes it
Jorge
@OrangeKulture
Sep 29 2017 14:11
it will execute everytime it loops
ehutchllew
@ehutchllew
Sep 29 2017 14:11
React is A-OK in my book
Ian Gracia
@iangracia
Sep 29 2017 14:11
what do u mean
Jorge
@OrangeKulture
Sep 29 2017 14:11
ahh ok ok sry ! my bad .. i didnt see the brackets
Ian Gracia
@iangracia
Sep 29 2017 14:11
no problem my mna
man
im trying putting an else if statement checking if its undefined now, not working very well
Jorge
@OrangeKulture
Sep 29 2017 14:12
@iangracia try switching the variable names and see if it helps, otherwise your solution should pass
CamperBot
@camperbot
Sep 29 2017 14:12
orangekulture sends brownie points to @iangracia :sparkles: :thumbsup: :sparkles:
api offline
heroiczero
@heroiczero
Sep 29 2017 14:12
@iangracia personally, i would do
 function nestArray(a){
    if(!Array.isArray(a)){
      newArr.push(a);
    }
    else{
      for(var i=0;i<a.length;i++){
        nestArr(a[i]);
      }
    }
  }
arr.forEach(nestArray);
Ian Gracia
@iangracia
Sep 29 2017 14:13
would that flatten the array? @heroiczero
Jorge
@OrangeKulture
Sep 29 2017 14:13
function steamrollArray(arr) {
  // I'm a steamroller, baby
  var newArr = [];

  function nestArray(arr) {   // -< change this arr to something else
   for (var i=0; i<arr.length[i]; i++){    // -< change this arr to something else
    if (Array.isArray(arr[i])) {// -< change this arr to something else
        nestArray(arr[i]);         // -< change this arr to something else
    } 

        newArr.push(arr[i]);       
   }
  }


  nestArray(arr);
  return newArr;
}

steamrollArray([1, [2], [3, [[4]]]]);
you tried it!
@you-tried-it
Sep 29 2017 14:14

public class Arrays {
public static void main(String[] args){
double[]myList={1.9,2.9,3.4,3.5};

    //print all the array elements
    for (int i= 0; 1< myList.length; i++){
        System.out.println(myList[i]+ " ");
    }
    //summing all elements
    double total = 0;
    for(int i=0; i< myList.length; i++){
        total += myList[i];
    }
    System.out.println("Total is "+ total);

    //finding the largest element
    double max = myList[0];
    for(int i=1; i <myList.length; i++){
        if(myList[i] > max) max = myList[i];            
    }
    System.out.println("Max is" + max);
}

}

heroiczero
@heroiczero
Sep 29 2017 14:14
@you-tried-it
public class Arrays {
    public static void main(String[] args){
        double[]myList={1.9,2.9,3.4,3.5};

        //print all the array elements
        for (int i= 0; 1< myList.length; i++){
            System.out.println(myList[i]+ " ");
        }
        //summing all elements
        double total = 0;
        for(int i=0; i< myList.length; i++){
            total += myList[i];
        }
        System.out.println("Total is "+ total);

        //finding the largest element
        double max = myList[0];
        for(int i=1; i <myList.length; i++){
            if(myList[i] > max) max = myList[i];            
        }
        System.out.println("Max is" + max);
    }

}
you tried it!
@you-tried-it
Sep 29 2017 14:14
... why?
Jorge
@OrangeKulture
Sep 29 2017 14:14
anyone here deploys to heroku ?
you tried it!
@you-tried-it
Sep 29 2017 14:15
@heroiczero thanks! :+1: how did you do that?
CamperBot
@camperbot
Sep 29 2017 14:15
api offline
you-tried-it sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
Jorge
@OrangeKulture
Sep 29 2017 14:15
cbot
CamperBot
@camperbot
Sep 29 2017 14:15
you called?
Jorge
@OrangeKulture
Sep 29 2017 14:15
allyourbase
CamperBot
@camperbot
Sep 29 2017 14:15
all your base
heroiczero
@heroiczero
Sep 29 2017 14:15
@you-tried-it ''' :point_down:
CamperBot
@camperbot
Sep 29 2017 14:15
:bulb: to format code use backticks! ``` more info
Ian Gracia
@iangracia
Sep 29 2017 14:15
@OrangeKulture i tried that, didnt work
Jorge
@OrangeKulture
Sep 29 2017 14:15
lol .. so u do have time for memes but not for brownies huh
@iangracia try refreshing the page .. your solution is correct
CamperBot
@camperbot
Sep 29 2017 14:16
orangekulture sends brownie points to @iangracia :sparkles: :thumbsup: :sparkles:
api offline
Ian Gracia
@iangracia
Sep 29 2017 14:16

function steamrollArray(arr) {
  // I'm a steamroller, baby
  var newArr = [];


  function nestArray(a) {
   for (var i=0; i<a.length; i++){    
    if (Array.isArray(a[i])) {
        nestArray(a[i]);         
    } 


     newArr.push(a[i]);       
   }
  }


  nestArray(arr);
  return newArr;
}

steamrollArray([1, [2], [3, [[4]]]]);
This is where im at now
you tried it!
@you-tried-it
Sep 29 2017 14:17
@heroiczero thx ;) :kissing_cat: :clap:
CamperBot
@camperbot
Sep 29 2017 14:17
you-tried-it sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
api offline
Ian Gracia
@iangracia
Sep 29 2017 14:17
it returns [1,2,[2],3,4,[4],[[4]],[3,[[4]]]]
its because at the recursion, the a.length is still 3 instead of 1 when its doing a recursion on [2]
Jorge
@OrangeKulture
Sep 29 2017 14:18
function nestArray(a) {
   for (var i=0; i<a.length; i++){    
    if (Array.isArray(a[i])) {
        nestArray(a[i]);         
     } else {
        newArr.push(a[i]);   
   }

   }
  }
Ian Gracia
@iangracia
Sep 29 2017 14:19
@OrangeKulture you know what im saying?
Jorge
@OrangeKulture
Sep 29 2017 14:19
yeah definitely.. recursion is a biatch ... still, u should get the correct response. Try adding the else statement
i just typed this out and it passes:
function steamrollArray(arr) {
  var resp = [];

  function shortArray(val){
    for(var i =0;i<val.length;i++){
      if(Array.isArray(val[i])){
        shortArray(val[i]);
      }else
      resp.push(val[i]);
    }

  }
  shortArray(arr);
  return resp;

}

steamrollArray([1, [2], [3, [[4]]]]);
Ian Gracia
@iangracia
Sep 29 2017 14:20
what
i cant find the difference :cry:
Markus Kiili
@Masd925
Sep 29 2017 14:22
@iangracia It is also possible to change the logic a bit and do it without the inner function.
CamperBot
@camperbot
Sep 29 2017 14:22
masd925 sends brownie points to @iangracia :sparkles: :thumbsup: :sparkles:
:cookie: 338 | @iangracia |http://www.freecodecamp.com/iangracia
Jorge
@OrangeKulture
Sep 29 2017 14:22
yeah just loop if its not an array
Ian Gracia
@iangracia
Sep 29 2017 14:22
what is the difference?! I can't find it!
Jorge
@OrangeKulture
Sep 29 2017 14:23
me and cbot have an agreement ...
he makes my tests pass at the first go :joy:
Markus Kiili
@Masd925
Sep 29 2017 14:24
@iangracia Else before the push.
CamperBot
@camperbot
Sep 29 2017 14:24
api offline
masd925 sends brownie points to @iangracia :sparkles: :thumbsup: :sparkles:
Ian Gracia
@iangracia
Sep 29 2017 14:24
@Masd925 wtff, why does that matter?
Jorge
@OrangeKulture
Sep 29 2017 14:24
ive been pushing the else agenda since the get go .. but Ian wont do it
Ian Gracia
@iangracia
Sep 29 2017 14:25
it works now, i was just missing the else
someone care to explain it for my little brain?
i thought i didnt matter if u had an else or not
Markus Kiili
@Masd925
Sep 29 2017 14:25
@iangracia You don't push it if it is an array. Therefore the else.
CamperBot
@camperbot
Sep 29 2017 14:25
masd925 sends brownie points to @iangracia :sparkles: :thumbsup: :sparkles:
api offline
Moisés Man
@moigithub
Sep 29 2017 14:25
if/else mean this OR that.. not both
Jorge
@OrangeKulture
Sep 29 2017 14:25
if u dont include the else, it will execute that line of code on every loop
in retrospect, i should re write this algo ..
Ian Gracia
@iangracia
Sep 29 2017 14:26
ok thanks guys, here are your well deserved cookies @OrangeKulture @Masd925
CamperBot
@camperbot
Sep 29 2017 14:26
iangracia sends brownie points to @orangekulture and @masd925 :sparkles: :thumbsup: :sparkles:
:cookie: 470 | @orangekulture |http://www.freecodecamp.com/orangekulture
:star2: 4514 | @masd925 |http://www.freecodecamp.com/masd925
Jorge
@OrangeKulture
Sep 29 2017 14:26
was the best solution i could find at the time, but not so sure at that anymaao
Moisés Man
@moigithub
Sep 29 2017 14:27
it can be done with a single function (if i recall)
Markus Kiili
@Masd925
Sep 29 2017 14:27
function steamrollArray(arr) {
    if (Array.isArray(arr)) {
        var result = [];
        for (var i=0;i<arr.length;i++) {
            result = result.concat(steamrollArray(arr[i]));
        }
        return result;
    }
    else return arr;
}
One way.
Jorge
@OrangeKulture
Sep 29 2017 14:28
yeah i was thinking concat
Markus Kiili
@Masd925
Sep 29 2017 14:28
@OrangeKulture Nice exercise is to find a non-recursive solution.
Jorge
@OrangeKulture
Sep 29 2017 14:28
@Masd925 awesome stuff, thanks
CamperBot
@camperbot
Sep 29 2017 14:28
orangekulture sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4515 | @masd925 |http://www.freecodecamp.com/masd925
Jorge
@OrangeKulture
Sep 29 2017 14:29
yeah i need to go over all of my algos and do non recursive
Markus Kiili
@Masd925
Sep 29 2017 14:30
@OrangeKulture There is also an elegant one-liner for Steamroller.
Moisés Man
@moigithub
Sep 29 2017 14:32
[1, [2], [3, [[4]]]].toString().split(",")
Ian Gracia
@iangracia
Sep 29 2017 14:32
@Masd925 that would be something to see
Markus Kiili
@Masd925
Sep 29 2017 14:33
@moigithub Description doesn't say what values the array elements can be, so toString doesn't work really.
Moisés Man
@moigithub
Sep 29 2017 14:34
...its supossed to be an array (with possibles nested arrays)
Markus Kiili
@Masd925
Sep 29 2017 14:35
@moigithub Array elements can be objects, which ruins it.
Moisés Man
@moigithub
Sep 29 2017 14:48
wonder what's the "elegant" one liner version.. cuz did one using reduce.. and doesnt seems pretty
[1, [2], [3, [[4]]]].reduce(function n(acum, val){return Array.isArray(val)? val.reduce(n,acum):acum.concat(val)},[])
with arrow functions
[1, [2], [3, [[4]]]].reduce(fn=(acum, val)=>Array.isArray(val)? val.reduce(fn,acum):acum.concat(val),[])
Markus Kiili
@Masd925
Sep 29 2017 14:58
@moigithub
function steamrollArray(arr) {
    return Array.isArray(arr) ? Array.prototype.concat.apply([],arr.map(steamrollArray)) : arr;
}
piteto
@piteto
Sep 29 2017 15:23
function steamrollArray(arr) {
  return Array.isArray(arr) ? [].concat.apply([], arr.map(steamrollArray)) : arr;
}
I don't think the Array.prototype is needed in that
My solution was:
function steamrollArray(arr) {
  const flat = [].concat(...arr);
  return flat.find(Array.isArray) ? steamrollArray(flat) : flat;
}
edisket
@edisket
Sep 29 2017 15:24
Are you guys working with one project?
piteto
@piteto
Sep 29 2017 15:24
@edisket Are you talking about codepen projects?
edisket
@edisket
Sep 29 2017 15:25
Yes
Markus Kiili
@Masd925
Sep 29 2017 15:25
@piteto You can use either.
piteto
@piteto
Sep 29 2017 15:25
I'm using github to host mine @edisket https://github.com/piteto/piteto.github.io
Not familiar with codepen projects, except I know you can only have one with a free account
@Masd925 Yes, curious if one is more efficient than the other though
I need to start looking at prototypes...two days in a row this has come up!
Markus Kiili
@Masd925
Sep 29 2017 15:29
@piteto I would guess that [] might be slower, or the optimization makes them about equal.
piteto
@piteto
Sep 29 2017 15:37
@Masd925 Very good guess! https://jsperf.com/steamrollarray1 pretty much identical
alpox
@alpox
Sep 29 2017 17:12
@piteto I managed a much faster one - but its ugly :D
Just for the sake of the try
quickspeedy
@quickspeedy
Sep 29 2017 17:15

I am trying to figure out how to bypass iFrame and it seems like codepen refused to allow it to happen. Is there a work around issue for this code?
Issue:

//grab the a tag in share button and add href and a link to it.
  var tumbTag = document.getElementById('social-row').childNodes[3];
  tumbTag.setAttribute("href", "https://www.tumblr.com/widgets/share/tool?posttype=quote&tags=quotes&caption=" + author +"&content=" + quote + "&canonicalUrl=https%3A%2F%2Fwww.tumblr.com%2Fbuttons&shareSource=tumblr_share_button"
  );

Link to codepen: https://codepen.io/quickspeedy/pen/ZXLKXx

Twitter seems to work with the iFrame but not tumblr.

piteto
@piteto
Sep 29 2017 17:28
@alpox Nice work! Interesting though - faster in Chrome, but slower in Firefox. SpiderMonkey vs V8 showdown :p
alpox
@alpox
Sep 29 2017 17:31
@piteto Hm yea thats quite a bit strange :D
I have no idea what firefox did there ^^
piteto
@piteto
Sep 29 2017 17:36
@quickspeedy looks like you have a button inside an <a> tag, do this instead:
<a id="tumbBtn" target="_blank" class="btn btn-primary">Share</a>
quickspeedy
@quickspeedy
Sep 29 2017 17:37
That works but is there other ways to use an iframe? Or is that based on codepen security?
piteto
@piteto
Sep 29 2017 17:38
that's because of codepen's iframe security policy - tumblr may have an API like twitter that lets you work around it
quickspeedy
@quickspeedy
Sep 29 2017 17:39
Ok thanks! @piteto I'll look more into it.
CamperBot
@camperbot
Sep 29 2017 17:39
quickspeedy sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
:cookie: 166 | @piteto |http://www.freecodecamp.com/piteto
piteto
@piteto
Sep 29 2017 17:40
@quickspeedy I don't want to randomize you too much, the quote machine looks great :) but you could save a lot of code by using jQuery's .html() method to write your quote to the page.
  $("#divBox").html(
    "<h3>" + data.quote + "</h3>" +
    "<p class='mt-3'><h4><em> - " + data.author + "</em></h4></p>"
  );
(for example)
instead of all those createElement, appendChild calls
Matej Bošnjak
@mbosnjak01
Sep 29 2017 18:22
Hi. I've got some Angular JS problem ... when I include ui bootstrap like this angular.module("myUsers", ["ui.bootstrap"]) ... i get an error https://i.imgur.com/IJXd3ps.jpg ... necesary files are included in my app, but this gives mi this problem..could anyone help?
piteto
@piteto
Sep 29 2017 18:30
@mbosnjak01 use the unminified version of angular to get more debug information. You're likely missing a module
Matej Bošnjak
@mbosnjak01
Sep 29 2017 18:34
@piteto Module 'ui.bootstrap' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
i still don't quite get it cause I loaded it in my html file
and i didn't misspell either :|
piteto
@piteto
Sep 29 2017 18:34
Are you loading it after angular.js?
@mbosnjak01
Matej Bošnjak
@mbosnjak01
Sep 29 2017 18:35
yes
piteto
@piteto
Sep 29 2017 18:35
without seeing all the code, I don't know what else to say :/
this is my html
piteto
@piteto
Sep 29 2017 18:36
I don't see a .js extension at the end of your ui-bootstrap
Marouane R
@mrassili
Sep 29 2017 18:37
Hello
piteto
@piteto
Sep 29 2017 18:37
hello @mrassili
Matej Bošnjak
@mbosnjak01
Sep 29 2017 18:37
@piteto just added it, it was there before .. but still, error persist
piteto
@piteto
Sep 29 2017 18:38
if you can provide a live version to debug, I can try to take a closer look. Another thing you might want to try is moving all your .js files to the end of your HTML, before </body>
Marouane R
@mrassili
Sep 29 2017 18:38
Does someone know how to make a navbar sticky (sticky-top) on bigger screens only (md,lg ...) ?
is that even possible?
Matej Bošnjak
@mbosnjak01
Sep 29 2017 18:38
@piteto live version like, hosting it? I could tunnel you my localhost
ehutchllew
@ehutchllew
Sep 29 2017 18:39
@mbosnjak01 are you declaring its dependencies correctly?
piteto
@piteto
Sep 29 2017 18:39
@mrassili You can use media queries
@mbosnjak01 deploy it to codepen, github, or jsfiddle
Moisés Man
@moigithub
Sep 29 2017 18:39
@media screen and (min-width: 1000px) {
  .urNav { position:fixed; }
}
Matej Bošnjak
@mbosnjak01
Sep 29 2017 18:39
just a moment
Marouane R
@mrassili
Sep 29 2017 18:40
@piteto what is this?
@piteto can you elaborate?
piteto
@piteto
Sep 29 2017 18:40
@mrassili Kind of like in the code that @moigithub just showed. CSS Media Queries let you apply certain CSS properties based on the width of your web page
Marouane R
@mrassili
Sep 29 2017 18:42
@piteto @moigithub Great! Thank you two
CamperBot
@camperbot
Sep 29 2017 18:42
mrassili sends brownie points to @piteto and @moigithub :sparkles: :thumbsup: :sparkles:
:cookie: 167 | @piteto |http://www.freecodecamp.com/piteto
:star2: 3643 | @moigithub |http://www.freecodecamp.com/moigithub
Marouane R
@mrassili
Sep 29 2017 18:44
another issue :
why the navs don't stack vertically on mobile (in debug view) I am using the flex utilities though
Marouane R
@mrassili
Sep 29 2017 18:51
.
dilaniat
@dilaniat
Sep 29 2017 19:42
Hey guys! Is anyone around to take a look at my code and help me make my img show where I want it to? (It's probably super simple lol)
Jorge
@OrangeKulture
Sep 29 2017 19:45
@mrassili your navbar does stack on mobile screens
@dilaniat sure, whats up
Alexx Martínez
@AlexxMart
Sep 29 2017 20:58
I'm about to start the "Twitch JSON API" project and there are some hints in the project that are references to changes to the API and are for the Twitch API v5 which is no longer in use
after reading the Twitch documentation it seems that the only method available to use their API involves the use of a Tokken
does anyone here has an idea on how I can go about completing this project without the need of the tokkens, or how can I do it in spite of that?
Alexx Martínez
@AlexxMart
Sep 29 2017 21:06
@gothamknight that base URL unfortunately leads to the same error as it is deprecated and was replaced with the new API
Coy Sanders
@coymeetsworld
Sep 29 2017 21:18
@AlexxMart I used the ajax method over the getJSON, that way I could pass the client id in as part of the request. getJSON you can't do that
and I didn't have to use that URL either, I used the api.twitch.tv request over https
Alexx Martínez
@AlexxMart
Sep 29 2017 21:30
@coymeetsworld cool, I will try that. How did you get the client ID, did they provide that to you?
piteto
@piteto
Sep 29 2017 21:32
@AlexxMart You don't need a client id - I just did that project a couple weeks ago. You can use the wind-bow.glitch.me URLs provided
to see a different channel, replace freecodecamp at the end of the URL
Alexx Martínez
@AlexxMart
Sep 29 2017 21:37
@piteto that explains a part that I wasn't understanding about the instructions. Thanks a lot
CamperBot
@camperbot
Sep 29 2017 21:37
alexxmart sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
:cookie: 169 | @piteto |http://www.freecodecamp.com/piteto
piteto
@piteto
Sep 29 2017 21:38
no problem! the instructions weren't very clear - it took me some time to get started
@coymeetsworld the twitch.tv API accepts a client_id parameter in the query string if you ever want to try it with getJSON
"https://api.twitch.tv/kraken/channels/{CHANNEL NAME}?client_id={YOUR CLIENT ID}&callback=?"
Coy Sanders
@coymeetsworld
Sep 29 2017 21:40
hmm interesting @piteto, idk I made this change a long time ago
wonder if that was part of the API when I worked on it, it may not have or else I probably would've done that
piteto
@piteto
Sep 29 2017 21:40
I don't know when they allowed it, but I remembered seeing some examples when going through what Alexx just did
Coy Sanders
@coymeetsworld
Sep 29 2017 22:00
I see
you tried it!
@you-tried-it
Sep 29 2017 22:21
:)
Alexx Martínez
@AlexxMart
Sep 29 2017 22:23
hey @piteto I tried using the URLs you showed just to try, but the console keeps giving me the error "Reason: CORS header ‘Access-Control-Allow-Origin’ missing"
piteto
@piteto
Sep 29 2017 22:24
@AlexxMart Could you show your code?
sorry, I forgot
piteto
@piteto
Sep 29 2017 22:25
$.getJSON('https://wind-bow.glitch.me/twitch-api/channels/freecodecamp')
  .then(function(data) {
    console.log(data);
  });
this is what I just tried, and it works for me
@AlexxMart replace gomix.me with glitch.me in your URL
Alexx Martínez
@AlexxMart
Sep 29 2017 22:27
Awesome
piteto
@piteto
Sep 29 2017 22:27
@you-tried-it Did you get the java help you needed?
Alexx Martínez
@AlexxMart
Sep 29 2017 22:27
I was using the base URL in the excersice and that was the problem. Thanks again @piteto and sorry for bothering
CamperBot
@camperbot
Sep 29 2017 22:28
alexxmart sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
api offline
piteto
@piteto
Sep 29 2017 22:28
No problem @AlexxMart don't know why they haven't updated the instructions. I literally hit every problem you are hitting when I did this :p
Alexx Martínez
@AlexxMart
Sep 29 2017 22:29
@piteto at least that show's I'm not so lost then, believe me when I say that I've been looking above and beyond to look for a solution and it wasn't working
piteto
@piteto
Sep 29 2017 22:30
when searching on google, add "free code camp" to your searches - everyone seems to be hitting these same problems and stack overflow has helped me a lot
Barbara Pentoney
@flyfishingbarbara
Sep 29 2017 23:35
@OrangeKulture hey jorge-i was asking about sky....what do you mean 'a better place'...?