These are chat archives for FreeCodeCamp/Help

28th
Jun 2015
Steven Leiva
@StevenXL
Jun 28 2015 00:00
I am attempting it inside the "sucesss" function to getJSON.
David Wilbanks
@dwilbank68
Jun 28 2015 00:00
screen view?
Steven Leiva
@StevenXL
Jun 28 2015 00:00
you'd like me to past the code?
$(document).ready(function() {
  // on document ready
  var baseEndpoint = "https://api.twitch.tv/kraken/streams/"
  var users = ["medrybw", "freecodecamp", "storbeck", "terakilobyte", "habathcx","RobotCaleb","comster404","brunofin","thomasballinger","noobs2ninjas","beohoff"]
  var JSONP = "?callback=?"

  var streamInfo = [];

  // for each user
  users.forEach(function(currUser) {
    // make a request to the API
    $.getJSON(baseEndpoint + currUser + JSONP, function(data) {
      // gather and format information for user
      var user = {};

      // userName
      user["userName"] = currUser;

      // streamStatus
      if (data["stream"] === null) {
        user["streamStatus"] = "user-off";
      }
      else {
        user["streamStatus"] = "user-on";
      }

      // img
      if (user["streamStatus"] === "user-on") {
        user["img"] = data["stream"]["channel"]["logo"];
      }
      else {
        user["img"] = "http://static-cdn.jtvnw.net/jtv-static/404_preview-300x300.png";
      }

      // add user object to streamInfo
      streamInfo.push(user);
    });
  });

  console.log(streamInfo);
});
I did a console.log for each user inside the callback to getJSON, so I know that the data from the API is coming in fine.
But I can't seem to get each user "out" of the function I pass to getJSON.
I thought that since I declared that array before the call to getJSON, getJSON would have access to it (unless I am again mistaking how closures work).
David Wilbanks
@dwilbank68
Jun 28 2015 00:04
so streamInfo is blank, you say?
Steven Leiva
@StevenXL
Jun 28 2015 00:04
Yea.
it's an empty array. :-(
David Wilbanks
@dwilbank68
Jun 28 2015 00:04
cuz it is outside of the callback and it is printed before the value exists
console log it inside the callback and check...
ciper99
@ciper99
Jun 28 2015 00:04
guys I think there is something wrong with bonfire drop it
David Wilbanks
@dwilbank68
Jun 28 2015 00:04
you should get multiple console logs
as the array is built
Steven Leiva
@StevenXL
Jun 28 2015 00:05
@dwilbank68 that's exactly what happened. I got multiple logs, and the end of the array it was 11 elements long.
Why doesn't it exist outside of the call to getJSON?
I need to get the data out of there anyway.
David Wilbanks
@dwilbank68
Jun 28 2015 00:07
I believe it is standard practice NOT to get the data out of there. You have to do all your work inside of there.
I am waiting for an expert to tell me otherwise.
So how to keep from doing your work 11 times?
Steven Leiva
@StevenXL
Jun 28 2015 00:07
oooh
David Wilbanks
@dwilbank68
Jun 28 2015 00:07
build a condition to only do the condition once the array is 11 members long.
That's all the info I could get. I bet there's a better way though.
Steven Leiva
@StevenXL
Jun 28 2015 00:08
@dwilbank68 unless I am missing something, it seems like doing it that way is inefficient.
David Wilbanks
@dwilbank68
Jun 28 2015 00:08
Maybe. I couldn't get a better answer...
Steven Leiva
@StevenXL
Jun 28 2015 00:08
Because when a user clicks on "Online", I can't filter the data I already have, I have to do another 11 calls to teh API.
Same when the user clicks on "offline".
I thought maybe by getting the data out of the getJSON call, I can copy the array and then filter it for all, online, offline, depending on the user's clicks.
David Wilbanks
@dwilbank68
Jun 28 2015 00:09
I believe I filled 3 arrays at once, using filter. I think I did, anyway.
Steven Leiva
@StevenXL
Jun 28 2015 00:09
lol
David Wilbanks
@dwilbank68
Jun 28 2015 00:09
No, that's how I started...
Steven Leiva
@StevenXL
Jun 28 2015 00:10
OK - thank you very much for your help.
David Wilbanks
@dwilbank68
Jun 28 2015 00:10
yep
Steven Leiva
@StevenXL
Jun 28 2015 00:10
I have to spend some time with the family
David Wilbanks
@dwilbank68
Jun 28 2015 00:10
later sir
Steven Leiva
@StevenXL
Jun 28 2015 00:10
Same to you!
David Wilbanks
@dwilbank68
Jun 28 2015 00:11
for reference, making another call for each button press is probably the best way anyway, to get the freshest info
Brett Guillory
@kurzninja
Jun 28 2015 00:34
well, i'm guessing that the way I solved Pairwise was probably not the intended solution to the problem
but it passed
ciper99
@ciper99
Jun 28 2015 00:53
guys I need help with steamroller
the bonfire
what I was thinking of doing was
Mike Semko
@MadOgre
Jun 28 2015 00:53
@ciper99 what's up
ciper99
@ciper99
Jun 28 2015 00:53
use arr.forEach to go through every element in the array
inside the forEach
check if the element I'm currently on is an array with Array.isArray()
if it is
I wanted to use another array.forEach, this time to go through the element
and in that second forEach
Mike Semko
@MadOgre
Jun 28 2015 00:54
The way some of the test examples are it seems this is the best case for a recursive solution
because each of the arrays may have many levels of inclusion
ciper99
@ciper99
Jun 28 2015 00:55
splice the original array, adding all the elements of element through it, and after the second for each runs, delete the element array
is there anything wrong with my way?
or am I just translating it poorly to code?
Mike Semko
@MadOgre
Jun 28 2015 00:56
Nothing so far but how will you handle arrays like this [[[45]]]
ciper99
@ciper99
Jun 28 2015 00:56
well, that array only has one element,
so it would go through that element, and check if it is an array
since it is an array
it would splice the original array, adding to it the elements of the nested array and then removing the original element
then, the original array would be composed of almost the same array, except it would have lost a pair of []
so on, so forth
until the array is flattened
right?
Mike Semko
@MadOgre
Jun 28 2015 00:58
Yes but how will you know that it's flattened.
ciper99
@ciper99
Jun 28 2015 00:59
because of the if statement
in my forEach
maybe I can write it out in pseudocode?
Mike Semko
@MadOgre
Jun 28 2015 00:59
Oh I see. Can I see your code?
ciper99
@ciper99
Jun 28 2015 00:59
my code doesn't work
I can give it to you
Mike Semko
@MadOgre
Jun 28 2015 00:59
That's ok, paste it anyway.
ciper99
@ciper99
Jun 28 2015 01:00
but I'm afraid it will not translate what I want
Mike Semko
@MadOgre
Jun 28 2015 01:00
I will show you how I did mine too, but let's try to work out your way first
ciper99
@ciper99
Jun 28 2015 01:00
function steamroller(arr) {
  // I'm a steamroller, baby
  arr.forEach(function flatten(element){
    if (Array.isArray(element)){
      console.log(arr);
      element.forEach(function(elem){
        arr = arr.splice(arr.indexOf(element) + element.indexOf(elem) + 1, 0, elem);
        console.log(arr);
      arr = arr.splice(arr.indexOf(element), 1);
      });
    }
  });
  return arr;
}
so, what I want to do with that code is
at first, go through each element of the given array
check if the element is an array
if so
go through each element in the array
and add it to the original array using splice
then, after having added all the elements inside element
I want to delete element, using splice again
but it doesn't work
Also
that part, where it says
arr.indexOf(element) + element.indexOf(elem) + 1
what I mean by it is
get the index of the original element in the original array, and add it to the index of the element of the nested array and add it to 1
so that I will splice it in front of the element
and that it gets checked
so, in the given example
steamroller([1, 2, [3, [[4]]]]);
it would go through the first element without doing anything, and then since the second one is an array
it will splice the array in the argument, putting in index 3 the number 2, and then it deletes the array with 2 inside
does this make any sense?
or am I crazy @MadOgre
Mike Semko
@MadOgre
Jun 28 2015 01:05
No, you are not, but it seems a bit complicated. However that may be the price to pay for doing it non-recursively
I am trying to go through it
ciper99
@ciper99
Jun 28 2015 01:06
yeah, I still don't feel at home without recursion
I saw it once
it was beautiful
but I don't dominate it enough to think recursively
I hope the functional programming waypoint helps with that
Mike Semko
@MadOgre
Jun 28 2015 01:07
here is my recursive solution just for comparison
function steamroller(arr) {
  var result = [];
  for (var i = 0; i < arr.length; ++i) {
    if (Array.isArray(arr[i])) {
      result = result.concat(steamroller(arr[i]));
    } else {
      result = result.concat(arr[i]);
    }
  }
  return result;
}

steamroller([1, [2], [3, [[4]]]]);
here is my recursive solution just for comparison
function steamroller(arr) {
  var result = [];
  for (var i = 0; i < arr.length; ++i) {
    if (Array.isArray(arr[i])) {
      result = result.concat(steamroller(arr[i]));
    } else {
      result = result.concat(arr[i]);
    }
  }
  return result;
}

steamroller([1, [2], [3, [[4]]]]);
ciper99
@ciper99
Jun 28 2015 01:08
beautiful indeed
Mike Semko
@MadOgre
Jun 28 2015 01:08
I am still trying to understand how your splice line works
ciper99
@ciper99
Jun 28 2015 01:09
yeah, the splice line is wrong
I'm not sure how, but it is
Mike Semko
@MadOgre
Jun 28 2015 01:10
Do you fully understand what splice does ?
ciper99
@ciper99
Jun 28 2015 01:10
yes
splice adds and/or removes elements from arrays
the first argument is the index at which we start
the second one is the number of elements we eliminate
the third one is the element we put there
right?
Mike Semko
@MadOgre
Jun 28 2015 01:11
Yes that's right
Ok so lets dissect this line
arr = arr.splice(arr.indexOf(element) + element.indexOf(elem) + 1, 0, elem);
ciper99
@ciper99
Jun 28 2015 01:12
yeah what I wanted was
to put the elements inside of element, in order inside the array, after element
so, in the example with the second argument 2
Mike Semko
@MadOgre
Jun 28 2015 01:14
Oh ok I understand your logic
ciper99
@ciper99
Jun 28 2015 01:14
no need for example then?
Mike Semko
@MadOgre
Jun 28 2015 01:14
It actually should work but the line needs to be rewritten
first of all there is no reason to use indexOf anywhere because it doesn't always work for what you want
ciper99
@ciper99
Jun 28 2015 01:16
it should, like, my logic makes sense, right? it's the implementation
Mike Semko
@MadOgre
Jun 28 2015 01:16
indexOf is a costly operationthat performs a search through the array every time
and it returns the first index so if the array is [2,4,2,7] indexOf(2) will return 1 every time
The better way would be to use the index parameter of the function that is passed to forEach
forEach accepts a callback function as an argument
it's full signature is function(value, index, array) {}
use the index parameter to find out the current index
ciper99
@ciper99
Jun 28 2015 01:18
I gotta ask
are you a professional js guy?
How much experience you have?
just today
I was here, trying to understand that callback function thingy
no one knew how to use it
Mike Semko
@MadOgre
Jun 28 2015 01:19
I can explain it to you
ciper99
@ciper99
Jun 28 2015 01:19
and you also understand recursion
yeah I got it now, I think
but please, explain, you seem like you know your sh*t
Mike Semko
@MadOgre
Jun 28 2015 01:20
I am a professional programmer, but I am new to javascript in particular. But all these things like callbacks and recursion are similar to a lot of other languages I know
I program in C++/Java/PHP/C#/VB and a couple other more obscure ones
I am also a programming instructor
ciper99
@ciper99
Jun 28 2015 01:22
oh that makes sense
it's not hard to spot the pro :)
Mike Semko
@MadOgre
Jun 28 2015 01:22
So anyway, the thing with callbacks is this: Javascript treats functions like objects that can be copied pasted and passed around
Like you can make a function and then save it to a variable and then copy it somewhere else and then finally call it
Also you can make a function that accepts ANOTHER FUNCTION as a parameter to do part of the work
It's a little bit of an advanced concept, and not every language has it
ciper99
@ciper99
Jun 28 2015 01:24
like, var myFunc = function(otherFunc){}?
Mike Semko
@MadOgre
Jun 28 2015 01:24
exactly
I will show you.
ciper99
@ciper99
Jun 28 2015 01:24
and those arguments you mention are the arguments of otherFunc?
Mike Semko
@MadOgre
Jun 28 2015 01:24
right
ciper99
@ciper99
Jun 28 2015 01:25
:)
Mike Semko
@MadOgre
Jun 28 2015 01:25
so suppose I have a function that takes a single number and another function that will actually do something to this number
var f = function(number, funct) {

}
This function will take a number but instead of doing something with it, it will pass it to the function it receives as funct to actually do the work
var f = function(number, funct) {
   funct(number);
}
Do you see what I did there ?
ciper99
@ciper99
Jun 28 2015 01:28
yeah
all that f does
is get a number, pass it on to funct
and let funct do the magic work
Mike Semko
@MadOgre
Jun 28 2015 01:28
That's right exactly
ciper99
@ciper99
Jun 28 2015 01:28
what is the point though?
why not just pass number into funct directly?
Mike Semko
@MadOgre
Jun 28 2015 01:29
So this means that in order to correctly call f I must provide a number AND a function AND the function I pass must have at least one parameter
In this case there is no reason to use it so you are right, this is just an example
ciper99
@ciper99
Jun 28 2015 01:29
yup, and the parameter we pass to funct is the same we pass to f
oh ok!
Mike Semko
@MadOgre
Jun 28 2015 01:30
BUT sometimes there is a really good reason.
like in case of forEach
forEach also takes a function and then runs it on every item in the array
It's very convenient
that way you can separate a loop from what actually needs to get done to the elements
ciper99
@ciper99
Jun 28 2015 01:31
oh, so that we can specify funct, and what forEach does is loop through all elements, run funct on all of them
right?
Mike Semko
@MadOgre
Jun 28 2015 01:31
exactly
ciper99
@ciper99
Jun 28 2015 01:31
instead of going for (var i = 0; i < arr.length; i++){ funct(arr[i]);}
am I getting it=
Mike Semko
@MadOgre
Jun 28 2015 01:32
yes precisely
ciper99
@ciper99
Jun 28 2015 01:32
hehe
great, now I understand callbacks
jlin14
@jlin14
Jun 28 2015 01:32
can anyone explain whats going on with the syntax inside the terenary operator
Array.prototype.push.apply(result, Array.isArray(item) ? self(item) : [item]);
Mike Semko
@MadOgre
Jun 28 2015 01:32
Instead of that line you wrote you can just write arr.forEach(funct);
ciper99
@ciper99
Jun 28 2015 01:33
what I don't know, is how can I access funct's arguments inside f?
Mike Semko
@MadOgre
Jun 28 2015 01:34
@ciper99 You can't. You have to be inside funct for that
But you don't usually need to
Let's look at your code again
function steamroller(arr) {
  // I'm a steamroller, baby
  arr.forEach(function flatten(element){
    if (Array.isArray(element)){
      console.log(arr);
      element.forEach(function(elem){
        arr = arr.splice(arr.indexOf(element) + element.indexOf(elem) + 1, 0, elem);
        console.log(arr);
      arr = arr.splice(arr.indexOf(element), 1);
      });
    }
  });
  return arr;
}
ciper99
@ciper99
Jun 28 2015 01:35
yeah, how am I supposed to change that?
Mike Semko
@MadOgre
Jun 28 2015 01:35
First of all let's fix some little problems
ciper99
@ciper99
Jun 28 2015 01:36
ok!
Mike Semko
@MadOgre
Jun 28 2015 01:36
when you pass flatten as a callback to foreach, it doesn't really need a name
simply pass function(element)
ciper99
@ciper99
Jun 28 2015 01:36
yeah, I know, look at the seconf for each!
I don't also need
to write arr = arr.splice, do I?
was that the next thing?
that array.splice changes the array?
Mike Semko
@MadOgre
Jun 28 2015 01:37
yes
because it doesn't return what you expect
it returns only the things that were removed or [] in your case
ciper99
@ciper99
Jun 28 2015 01:38
:)
I previously didn't have it there
however
the code wasn't working
so I kinda went paranoid
Mike Semko
@MadOgre
Jun 28 2015 01:38
Now remember what I told you about callbacks
ciper99
@ciper99
Jun 28 2015 01:38
and started trying different thing
like, adding a name to the callback function and stuff
Mike Semko
@MadOgre
Jun 28 2015 01:38
The function that you are supposed to pass to forEach has 3 arguments not 1
ciper99
@ciper99
Jun 28 2015 01:38
to see if that was what was going wrong
Mike Semko
@MadOgre
Jun 28 2015 01:39
the arguments are value, index, and array
ciper99
@ciper99
Jun 28 2015 01:39
yes...
Mike Semko
@MadOgre
Jun 28 2015 01:39
Let me paste it with the changes so far
function steamroller(arr) {
  // I'm a steamroller, baby
  arr.forEach(function(value, index, array){
    if (Array.isArray(value)){
      console.log(arr);
      element.forEach(function(elem){
        arr = arr.splice(arr.indexOf(element) + element.indexOf(elem) + 1, 0, elem);
        console.log(arr);
      arr = arr.splice(arr.indexOf(element), 1);
      });
    }
  });
  return arr;
}
This is not all fixed yet
Only down to line 4
ciper99
@ciper99
Jun 28 2015 01:43
oh ok!
so, now we gotta put value, index, array in the elements of the second callback function, right?
Mike Semko
@MadOgre
Jun 28 2015 01:43
yes but make sure they are named something different
like value2, index2, array2
ciper99
@ciper99
Jun 28 2015 01:44
ok chief
let me try it out with the changes
Mike Semko
@MadOgre
Jun 28 2015 01:45
hold on, did you make sure to change all the "element" to value and "elem" to value2
Can you tell me why you have a +1 in your splice line ?
ciper99
@ciper99
Jun 28 2015 01:46
yes
it's so that it gets added not in the current index
but in the next index
to make sure it looks through it
because without the +1, the first value2 would be where value is
is that unnecessary, since I splice the array again later?
Mike Semko
@MadOgre
Jun 28 2015 01:47
oh I see that's why you delete the first element at the end ?
ciper99
@ciper99
Jun 28 2015 01:48
yeah
to make sure that
the value at index
is always the same until the end
otherwise, it would overwritten in the first instance of the second forEach
right?
but maybe it isn't needed
since it was passed as an argument to the first forEach, and I can access the value using the argument?
Mike Semko
@MadOgre
Jun 28 2015 01:49
No, no I think you are right
ciper99
@ciper99
Jun 28 2015 01:49
yeah, I think it simplifies things
Mike Semko
@MadOgre
Jun 28 2015 01:50
But something doesn't seem quite right, because the last splice would keep deleting the first element for every element
For example suppose you have this example array [1, [2], [3, [[4]]]]
It would start going through the main array
Skip the first 2 because it's not an array
Now the index is 1
then it would see [2] which is an array
ciper99
@ciper99
Jun 28 2015 01:52
and it would first splice the array
turning it into
[1, 2, 2, [3, [[4]]]]
and then splice it again
removing the 2
Mike Semko
@MadOgre
Jun 28 2015 01:53
oh I see.
ok now I got it
So this should work
ciper99
@ciper99
Jun 28 2015 01:54
make any sense?
Mike Semko
@MadOgre
Jun 28 2015 01:54
yeah
just replace your arr.indexOf(element) with index and element.indexOf(elem) with index2
ciper99
@ciper99
Jun 28 2015 01:56
it isn't working though
function steamroller(arr) {
  // I'm a steamroller, baby
  arr.forEach(function (value, index, array){
    if (Array.isArray(value)){
      value.forEach(function(value2, index2, array2){
        arr = arr.splice(index + index2 + 1, 0, value2);

      arr = arr.splice(index, 1);
      });
    }
  });
  return arr;
}
I'm getting the same results
time for some debugging!
Mike Semko
@MadOgre
Jun 28 2015 01:58
yep. I tested it with the changes I got back an empty array
Is that what you got ?
ciper99
@ciper99
Jun 28 2015 01:59
yes
it was also what I had before
Mike Semko
@MadOgre
Jun 28 2015 02:00
Ok give me a minute let me look
The first splice like looks like its completely clearing the arr for some reason
oh nevermind forgot to remove the arr =
now it doesn't clear the array anymore but still wrong result
ciper99
@ciper99
Jun 28 2015 02:05
yeah and I see why
I had been reading up about this
I'm afraid that forEach only goes through each value once
it's only removing one pair of [] from the super nested array
Mike Semko
@MadOgre
Jun 28 2015 02:06
I was afraid of that
That's what I was worried about at the beginning
ciper99
@ciper99
Jun 28 2015 02:07
:(
I'll try to remedy that
at least I have your beautiful recursive solution though
Mike Semko
@MadOgre
Jun 28 2015 02:08
I thought it would work though...
ciper99
@ciper99
Jun 28 2015 02:08
hmmm, I had an idea
let me see
Mike Semko
@MadOgre
Jun 28 2015 02:08
Now I have to fix this non-recursively. It's a challenge :)
ciper99
@ciper99
Jun 28 2015 02:08
going to try to do without
forEach
just a regular loop
and, if I happen to find one of those super arrays
I'll just go back
wait
something worse
it removed the 3
Mike Semko
@MadOgre
Jun 28 2015 02:10
i know I already noticed that
ciper99
@ciper99
Jun 28 2015 02:10
Ah crap
this solution sucks
but I don't wanna submit your solution
Mike Semko
@MadOgre
Jun 28 2015 02:10
No we can do this, we can fix this
ciper99
@ciper99
Jun 28 2015 02:10
because it feels like cheating
Mike Semko
@MadOgre
Jun 28 2015 02:10
This logic is sound
it should work
ciper99
@ciper99
Jun 28 2015 02:11
because I don't understand recursion very well
Mike Semko
@MadOgre
Jun 28 2015 02:13
Apparently some guys on stack overflow think this problem cannot be done nonrecursively :)
ciper99
@ciper99
Jun 28 2015 02:13
really?
Mike Semko
@MadOgre
Jun 28 2015 02:13
This makes me want to do it more :)
ciper99
@ciper99
Jun 28 2015 02:13
where?
I thought all problems that could be solved recursively could be solved iteratively
JT Longino
@jtlongino
Jun 28 2015 02:14
I think my solution was recursive, also
Mike Semko
@MadOgre
Jun 28 2015 02:14
Yes that is true, which is why I now feel like doing it to prove them wrong
I think I know what the problem is with the 3
ciper99
@ciper99
Jun 28 2015 02:16
what is it?
Mike Semko
@MadOgre
Jun 28 2015 02:16
The second forEach doesn't check whether the element is an array
the 3 is not an array, it's just an element of one
ciper99
@ciper99
Jun 28 2015 02:17
hmmm, so maybe we should check if value 2 is an array?
JT Longino
@jtlongino
Jun 28 2015 02:26
there we go, a non-recursive solution
Mike Semko
@MadOgre
Jun 28 2015 02:27
It seems that what is happening is splice is failing to add elements 1 past the end of the array
@jtlongino where ?
JT Longino
@jtlongino
Jun 28 2015 02:28
function steamroller(arr) { // I'm a steamroller, baby var final_array = []; var array_of_arrays = true; while(array_of_arrays){ array_of_arrays = false; while(arr.length > 0){ element = arr.shift(); if(Array.isArray(element)){ array_of_arrays = true; element.forEach( function(item){ final_array.push(item);}); } else{ final_array.push(element); } } arr = final_array; final_array = []; } return arr; }
That's not the right markdown
function steamroller(arr) { // I'm a steamroller, baby var final_array = []; var array_of_arrays = true; while(array_of_arrays){ array_of_arrays = false; while(arr.length > 0){ element = arr.shift(); if(Array.isArray(element)){ array_of_arrays = true; element.forEach( function(item){ final_array.push(item);}); } else{ final_array.push(element); } } arr = final_array; final_array = []; } return arr; }
ciper99
@ciper99
Jun 28 2015 02:29
ctrl+alt+m for markdown help
Mike Semko
@MadOgre
Jun 28 2015 02:29
function steamroller(arr) {
  // I'm a steamroller, baby
  var final_array = [];
  var array_of_arrays = true;
  while(array_of_arrays){
    array_of_arrays = false;
    while(arr.length > 0){
      element = arr.shift();
      if(Array.isArray(element)){
        array_of_arrays = true;
        element.forEach( function(item){ final_array.push(item);});
      }
      else{
        final_array.push(element);
      }
    }
    arr = final_array;
    final_array = [];
  }
  return arr;
}
I got it
JT Longino
@jtlongino
Jun 28 2015 02:29
function steamroller(arr) {
  // I'm a steamroller, baby
  var final_array = [];
  var array_of_arrays = true;
  while(array_of_arrays){
    array_of_arrays = false;
    while(arr.length > 0){
      element = arr.shift();
      if(Array.isArray(element)){
        array_of_arrays = true;
        element.forEach( function(item){ final_array.push(item);});
      }
      else{
        final_array.push(element);
      }
    }
    arr = final_array;
    final_array = [];
  }
  return arr;
}
Still used to Slack markdown
ciper99
@ciper99
Jun 28 2015 02:30
hhehe
JT Longino
@jtlongino
Jun 28 2015 02:30
the forEach in the middle of the while is probably not awesome.
Mike Semko
@MadOgre
Jun 28 2015 02:30
probably not but that's why recursion rocks
JT Longino
@jtlongino
Jun 28 2015 02:31
I agree. My first solution was recursive.
Mike Semko
@MadOgre
Jun 28 2015 02:31
I can't believe how much harder this is without
ciper99
@ciper99
Jun 28 2015 02:31
yep it works
Mike Semko
@MadOgre
Jun 28 2015 02:32
Yeah @ciper99 I think splice is a pain in the neck
reconstructing the array seems to be the ticket
ciper99
@ciper99
Jun 28 2015 02:33
this is too complex for me, honestly
I feel like I'm way over my head
Mike Semko
@MadOgre
Jun 28 2015 02:33
which? recursion or the solution @jtlongino posted ?
JT Longino
@jtlongino
Jun 28 2015 02:33
Generally, changing the structure you're iterating over while you're iterating over it is going to be tricky.
ciper99
@ciper99
Jun 28 2015 02:34
I haven't finished reading up on his solution
I can clearly say that this exercise is better than me though
Mike Semko
@MadOgre
Jun 28 2015 02:34
@jtlongino yes, and in some languages it's not allowed at all
ciper99
@ciper99
Jun 28 2015 02:34
it was much harder than the other ones
mostly
because up until now
we haven't been introduced to recursion
I mean, not formally
like studying it, in the curriculum
only way ahead
so, they probably wanted an iterative solution
Mike Semko
@MadOgre
Jun 28 2015 02:35
Yeah this type of exercise normally screams "recursion"
ciper99
@ciper99
Jun 28 2015 02:35
yeah but, if you are not a programmer
like me
you don't know recursion well at this point
at least I don't
JT Longino
@jtlongino
Jun 28 2015 02:36
JS has some weird rules around forEach
ciper99
@ciper99
Jun 28 2015 02:36
and I didn't struggle with the other exercises
Mike Semko
@MadOgre
Jun 28 2015 02:36
I doubt they wanted a non-recursive solution, although I'm not sure
JT Longino
@jtlongino
Jun 28 2015 02:36
The range of elements processed by forEach() is set before the first invocation of callback. Elements that are appended to the array after the call to forEach() begins will not be visited by callback. If the values of existing elements of the array are changed, the value passed to callback will be the value at the time forEach() visits them; elements that are deleted before being visited are not visited.
ciper99
@ciper99
Jun 28 2015 02:37
yeah, but that ain't the problem
the problem is
it actually goes over the elements I create
but in the final instance
the element at index happens to be 3
and it eliminates it
and it also doesn't go through the other array again, since that index has been done
ahhhhh
I quit
Mike Semko
@MadOgre
Jun 28 2015 02:39
Just take a break and come back tomorrow with a clear head, and do it over without the splices. Something like a solution that @jtlongino just posted will do
ciper99
@ciper99
Jun 28 2015 02:39
at least I learned something
Mike Semko
@MadOgre
Jun 28 2015 02:40
I will be here later in the evening and I can explain recursion to you then
I am going AFK for 15 minutes
ciper99
@ciper99
Jun 28 2015 02:40
yeah, I mean, I grasp a bit of what it is
like, calling the same function inside of a function
very inception
it's 3:40am here
JT Longino
@jtlongino
Jun 28 2015 02:41
Hmm
Well, you don't want the final splice to be in the forEach
ciper99
@ciper99
Jun 28 2015 02:44
it isn't
the final splice is after the forEach
JT Longino
@jtlongino
Jun 28 2015 02:44
I might be looking at old code
Could you post what you have now?
ciper99
@ciper99
Jun 28 2015 02:45
here it goes
function steamroller(arr) {

  arr.forEach(function (value, index, array){
    if (Array.isArray(value)){

      value.forEach(function(value2, index2, array2){

        arr.splice(index + index2 + 1, 0, value2);


      arr.splice(index, 1);

      });
    }

  });
  return arr;

}
JT Longino
@jtlongino
Jun 28 2015 02:46
Yeah, the second arr.splice
ciper99
@ciper99
Jun 28 2015 02:46
wait, which forEach were you talking about?
JT Longino
@jtlongino
Jun 28 2015 02:46
arr.splice(index, 1);
ciper99
@ciper99
Jun 28 2015 02:46
it is outside the second forEach
oh wait
I had an idea
why not
instead of putting that there
just leaving it
like, the array
JT Longino
@jtlongino
Jun 28 2015 02:47
You'll need to get rid of it eventually
ciper99
@ciper99
Jun 28 2015 02:47
and then, go on with business, leaving the old nested arrays along with their flattened elements
and in the end
remove all arrays?
like, with array.filter()
Edwin Castillo
@edgcastillo
Jun 28 2015 02:47
Hey guys, I'm looking for some feedback. I've been doing the Bonfires and the tests pass all the time, but I'm not sure if I'm solving the challenges the correct way. Like this one:
ciper99
@ciper99
Jun 28 2015 02:47
that might work
@edgcastillo if it passes it is correct!
JT Longino
@jtlongino
Jun 28 2015 02:48
The problem with the code you have now is it can't handle the [3, [4]] nesting
you'll insert the 3, then insert [4]
Edwin Castillo
@edgcastillo
Jun 28 2015 02:48
function where(arr, num) {
    arr.push(num);
    return arr.sort(function(a,b){ return a - b;}).indexOf(num);
}

console.log(where([40, 60], 50)); // returns 1
console.log(where([10, 20, 30, 40, 50], 35)); // returns 3
console.log(where([10, 20, 30, 40, 50], 30)); // returns 2
I mean it works, but should I try in another way?
JT Longino
@jtlongino
Jun 28 2015 02:49
@edgcastillo That's actually a quite elegant way to solve that problem!
ciper99
@ciper99
Jun 28 2015 02:50
if you want to try it again, do so :)
what problem is that?
Mike Semko
@MadOgre
Jun 28 2015 02:50
I am afraid I have to say good night to you all for today. I forgot I have a meeting in the morning
ciper99
@ciper99
Jun 28 2015 02:50
lol, good night!
Mike Semko
@MadOgre
Jun 28 2015 02:51
We will resume tomorrow
Edwin Castillo
@edgcastillo
Jun 28 2015 02:51
Oh thanks, no problem is probably just me looking to much into a problem LOL
ciper99
@ciper99
Jun 28 2015 02:51
really thankful
thanks for your explanations!
Edwin Castillo
@edgcastillo
Jun 28 2015 02:51
Thanks!
JT Longino
@jtlongino
Jun 28 2015 02:52
@edgcastillo You could probably also solve it using Array.reduce if you wanted.
Edwin Castillo
@edgcastillo
Jun 28 2015 02:53
Ok, thanks!
JT Longino
@jtlongino
Jun 28 2015 02:53
@ciper99 Do you see what I meant about inserting the 3, then the [4] ?
ciper99
@ciper99
Jun 28 2015 02:55
uh, let me see
yeah I see it now
the logic was
the we insert 3, and leave the [4] in the following index
so forEach will run through it, no?
JT Longino
@jtlongino
Jun 28 2015 02:56
nope
forEach sets the range right when it's called
ciper99
@ciper99
Jun 28 2015 02:57
hmmm, what if I drop for each entirely?
and use a regular for loop?
JT Longino
@jtlongino
Jun 28 2015 02:57
You'll run into a similar problem there
ciper99
@ciper99
Jun 28 2015 02:58
hmmm, why?
JT Longino
@jtlongino
Jun 28 2015 02:58
The complexity you're running into is due to changing the structure of the thing you're iterating.
ciper99
@ciper99
Jun 28 2015 02:58
layman terms?
JT Longino
@jtlongino
Jun 28 2015 02:59
you're inserting and deleting items from the array you're looping over.
ciper99
@ciper99
Jun 28 2015 02:59
yes
why is that a problem?
JT Longino
@jtlongino
Jun 28 2015 02:59
It's complex.
Let's start with forEach.
You tell the program, "Okay, iterate over every element in this array and execute some function using the element as an argument"
ciper99
@ciper99
Jun 28 2015 03:01
yes
JT Longino
@jtlongino
Jun 28 2015 03:01
Technically, there's no guarantee that forEach acts on each element in order
It doesn't have to.
So it has to pick a time to determine what "every element in this array" is.
ciper99
@ciper99
Jun 28 2015 03:02
and it picks the beginning
JT Longino
@jtlongino
Jun 28 2015 03:02
That's right.
ciper99
@ciper99
Jun 28 2015 03:02
when it is called
is that so?
JT Longino
@jtlongino
Jun 28 2015 03:02
That is so.
ciper99
@ciper99
Jun 28 2015 03:03
so, why isn't it solved with a regular for?
JT Longino
@jtlongino
Jun 28 2015 03:03
You still have to deal with the index.
It's okay in this case, where the nested arrays are at the end.
ciper99
@ciper99
Jun 28 2015 03:04
I'll deal with it tomorrow I guess
I'm tired today :)
thanks!
JT Longino
@jtlongino
Jun 28 2015 03:04
Sure thing!
Ahsan Naveed
@ahsannaveed007
Jun 28 2015 03:12
Hi Everyone I am at Bonfire: Smallest Common Multiple. I am trying to come up with the while condition for my do-while loop.
function smallestCommons(arr) {

  //two values that will be pushed to the two respective arrays
  var value_1=arr[0];
  var value_2=arr[1];

  //loop variable
  var i=1;

  //two arrays that will keep growing untill they have the same number at same index
  var arr_1 = [arr[0]];
  var arr_2 = [arr[1]];

  do{
    value_1+=arr[0];
    value_2+=arr[1];

    //condition should be as such that the arrays will keep on growing untill
    //they hit the same value in this case it is 60.

    // so the end result should look like arr_1 = [1,2,3,....60]
    // and arr_2 = [5,10,15,...,60]

    arr_1.push(value_1);
    arr_2.push(value_2);

    i++;
  }while(// condition requires, my solution of arr_1[i]!==arr_2[i] didn't work);


  return arr_1;// you can check either of arrays arr1/arr2 they increment as expected
}


smallestCommons([1,5]);
Sam Rich
@samrichca
Jun 28 2015 03:45
did any of you solve the roman numeral bonfire without brute forcing it?
ronaldrdguez
@ronaldrdguez
Jun 28 2015 04:11
@samrichca What do you mean brute-forcing it?
Tammy
@howetc
Jun 28 2015 05:10
hello all
i'm new to programming and i'm going through the waypoints, I'm having difficulty with placement of !important to override a style inline
Tommy Izen
@TommyIzen
Jun 28 2015 05:12
I'm doing the "Create a Block Element Bootstrap Button" and am having a little trouble.
<button class='btn' class="btn-block">Like</button> doesn't work
Timothy Touch
@timtouch
Jun 28 2015 05:59
@TommyIzen If you want to add multiple classes, just separate them with a space. ex: <button class="firstclass secondclass thirdclass"></button>
Robert Ozimek
@robertozimek
Jun 28 2015 06:04
@ahsannaveed007 you can try something like }while(arr_1.indexOf(arr_2[i]) < 0);
since the smallest common multiple won’t necessarily be in the same position of the arrays thats why arr_1[i]!==arr[i] doesn’t work
David Wilbanks
@dwilbank68
Jun 28 2015 06:09
Robert Ozimek
@robertozimek
Jun 28 2015 06:15
@ahsannaveed007 for example
the smallest common multiple of 4 and 10 is 20
so arr_1 would be 4, 8, 12, 16, 20
and arr_2 would be 10, 20
so arr_1[4] === arr_2[1]
Terrell Vest
@MirPresT
Jun 28 2015 06:31
hey does anyone know if the create a person bonfire works ? Like will it pass a correct answer cause I feel there may be an issue with the tests...?..?
that would be amazing if someone could check for me ...someone who's already gone through it before... I think its broken
David Wilbanks
@dwilbank68
Jun 28 2015 06:33
you can get it to work if you don't try to use the new .prototype method
just stick 6 methods inside the object and it will pass
Terrell Vest
@MirPresT
Jun 28 2015 06:34
but the challenge is set up to use a new constructor..
David Wilbanks
@dwilbank68
Jun 28 2015 06:36
yep
and that constructor will have 6 methods inside it
not using the .prototype
I already put in a github issue about it
Surya Man Bajracharya
@Zurya
Jun 28 2015 06:41

Please help me understand the code below in plain English?

if (choice1 === choice2){
return("The result is a tie!");
}

//the block below is confusing.
else if (choice1 === "rock") {

    if (choice2 === "scissors"){
        return("rock wins");
    }
    else {
        return ("paper wins");
    }
}
tjstinso
@tjstinso
Jun 28 2015 06:42
having an issue with regex. I’m trying to create a new regex object that identifies strings based on the beginning values:
var str = “insertStringHere"
var a = new RegExp (‘\^’ + str);
[x,y,z].match(a);
match is only cathing the str instead of the anchor + str. Does anyone have any idea what is going on here?
Cristián Berríos
@crisberrios
Jun 28 2015 06:44
@Zurya it's a nested if...else it could also be written as else { if(....) }
@tjstinso double escape, as the \ also works for escaping characters inside strings
Corrie
@ioqren
Jun 28 2015 07:53

Hi! I'm trying to do the Arguments Optional bonfire and I got 4/5 of the tests to work, but I just can't figure out the last one :( It says

expect(add('http://bit.ly/IqT6zt')).to.be.undefined;expected [Function] to be undefined

I don't entirely understand how this all works. I'm not sure how to check whether the sub function has arguments or not. I think that's what I have to do anyway? Argh.

function add() {
 var operand = arguments[0]; 

  if(arguments.length > 1){
   if(typeof arguments[0] === 'number' && typeof arguments[1] === 'number'){
     return arguments[0] + arguments[1];
   }
 else{
   return undefined;
 }
   }

 return function(){
   if(typeof arguments[0] === 'number'){
     return arguments[0] + operand;
   }
 };
}
Corrie
@ioqren
Jun 28 2015 07:59
oh wait
Ryan Malm
@Rybar
Jun 28 2015 08:00
hahaha
Corrie
@ioqren
Jun 28 2015 08:00
all that time
didn't even think to check if the one argument was a number .-.
Ryan Malm
@Rybar
Jun 28 2015 08:01
I wasn't laughing at your problem, I was laughing at the link
rickroll
but yes, need to check for numbers
Stephanie Morrison
@Stephaceae
Jun 28 2015 08:47
Been working on this for hours - I think I’m missing some key information: I’m on Waypoint: Write Functions with jQuery - CodyAcademy track ‘Introduction to Functions’ part three: jQuery Functions and Selectors.
I’m not sure how to insert the id of the 4th child into the function to get it to fade away… here’s what I’ve tried:
<!DOCTYPE html>
<html>
    <head>
        <title>Simplify, Simplify</title>
        <script type='text/javascript' src='script.js'></script>
    </head>
    <body>
        <div> Remember!
            <ul>
                <li>
                    <ol>
                        <li>Start with the function keyword</li>
                        <li>Inputs go between ()</li>
                        <li>Actions go between {}</li>
                        <li>jQuery is for chumps!</li>
                    </ol>
                </li>
                <li>Inputs are separated by commas.</li>
                <li>Inputs can include other functions!</li>
            </ul>
        </div>   
    </body>
</html>
// Write your jQuery code on line 3!
<!-- $(document).ready(function() {
    var $target = li:nth-child(4) {
    $target.fadeOut('fast');}
});
-->

li:nth-child(4) {
    .fadeout('fast');
}
Jack Hsieh
@Powiee
Jun 28 2015 08:49
You would write the code within the function block
You are on a good path. To select with jQuery you would use $(selector)
Stephanie Morrison
@Stephaceae
Jun 28 2015 08:51
@thanks, the waypoints skip all this, I’ve been backtracking trying to learn id’s and selectors...
Jack Hsieh
@Powiee
Jun 28 2015 08:51
selectors are just css like syntax
Stephanie Morrison
@Stephaceae
Jun 28 2015 08:53
@Powiee that comment above was for you, not ‘thanks’!! ok… so instead of putting ‘document’ into the $() I could put… li:nth-child(4)… that wouldn’t quite work because I need to specify which list….
still stuck… how do I specify the fourth comment in the ordered list in a function?
Jack Hsieh
@Powiee
Jun 28 2015 08:56
$("selector")
It need to be a string. sorry forgot
Stephanie Morrison
@Stephaceae
Jun 28 2015 08:58
lol, i think that is the least of my problems!
the challenge is to make the 4th point ‘jQuery is for chumps’ fade out using script.js functions
looking at the first set of code up there… would the selector be ‘ordered list’? $(“ol”)?
or $(nth-child(4))
*$(“nth-child(4)”)
@Powiee any more guidance to be offered? :D
Jack Hsieh
@Powiee
Jun 28 2015 09:02
what you had was right li:nth-child(4)
Stephanie Morrison
@Stephaceae
Jun 28 2015 09:03
@Powiee trying out in codeacedemy
Jack Hsieh
@Powiee
Jun 28 2015 09:04
You don't need the } on line 4 and { on line 3
Stephanie Morrison
@Stephaceae
Jun 28 2015 09:06
point taken - removed - I was following pseudo-selector CSS format I just learnt...
it still doesn’t work… what should I be making the target?
Jack Hsieh
@Powiee
Jun 28 2015 09:07
can you show me the current code?
Stephanie Morrison
@Stephaceae
Jun 28 2015 09:07
Should I have a html, CSS and JavaScript reference for these types of dilemmas?
yup
// Write your jQuery code on line 3!
$("li:nth-child(4)").ready(function() {
    var $target = li:nth-child(4) 
    $target.fadeOut('fast');
});
if my selector in $() is the “li:nth-child(4)” should I then make my target something else?
Jack Hsieh
@Powiee
Jun 28 2015 09:08
the 2nd line should stay the same $(document).ready(function() {
Stephanie Morrison
@Stephaceae
Jun 28 2015 09:08
ahhh kk
Jack Hsieh
@Powiee
Jun 28 2015 09:09
what you want to do is on line 3 put the li... into the $("selector")
Stephanie Morrison
@Stephaceae
Jun 28 2015 09:10
TypeError: undefined is not a function (evaluating '$target.fadeOut('fast')')
$(document).ready(function() {
    var $target = "li:nth-child(4)" 
    $target.fadeOut('fast');
});
I’m not sure where to put the “li”/
?
Jack Hsieh
@Powiee
Jun 28 2015 09:11
You are almost there.
Stephanie Morrison
@Stephaceae
Jun 28 2015 09:12
IS there a logical leap I need to make or is there a rule I am missing?
Jack Hsieh
@Powiee
Jun 28 2015 09:12
Just need to remember with jQuery you surround selectors with $( )
for example to select the div I would use $("div")
Stephanie Morrison
@Stephaceae
Jun 28 2015 09:13
urg. remember! That info isn’t anywhere in this waypoint… I think these waypoints are jumping ahead too quickly for me
…backtracking…. I’ve done the $(“div) before...
Jack Hsieh
@Powiee
Jun 28 2015 09:16
CWelshE pointed out the solution on the other chat room
Stephanie Morrison
@Stephaceae
Jun 28 2015 09:16
$(document).ready(function() {
    var $target = "li:nth-child(4)" 
    $($target).fadeOut('fast');
});
GOT IT!!
Jack Hsieh
@Powiee
Jun 28 2015 09:17
That's one way to do it :)
Stephanie Morrison
@Stephaceae
Jun 28 2015 09:17
thanks, didn’t see CWelshE, thanks for the hints without striaghtout telling me!
lol, this section was on using variables… I think it would be much cleaner without throwing the variable in there… but!
Jack Hsieh
@Powiee
Jun 28 2015 09:18
Usually you want to put $("li:nth-child(4)") into the $target
Stephanie Morrison
@Stephaceae
Jun 28 2015 09:18
… was just about to go back and try that! lets see...
yup, works just fine with less fuss!
Jack Hsieh
@Powiee
Jun 28 2015 09:20
Have to agree the codecademy description wasn't very straightforward
Glad I could help :)
Stephanie Morrison
@Stephaceae
Jun 28 2015 09:21
naw, not only have you enforced how to properly use $() but told me the name of the thing in the $()…selector
thanks!
Nathan Dimitriades
@nathandim
Jun 28 2015 09:39
indeed, that specific exercise in codecademy was the one thing I hated
Stephanie Morrison
@Stephaceae
Jun 28 2015 09:41
please tell me they get a little more clear @nathandim ?
Nathan Dimitriades
@nathandim
Jun 28 2015 09:43
yep, that's the only exercise that I had to check their forums/google
that's why it threw me off
Stephanie Morrison
@Stephaceae
Jun 28 2015 09:45
whew, that’s relief, I spent hours going through the basic html and CSS codeacademy stuff trying to workout what background I was missing
tjstinso
@tjstinso
Jun 28 2015 10:50
hmmm anyone have any trouble with codepen displaying differently than your own browser?
Joe Balsamo
@Joe-Balsamo
Jun 28 2015 11:08
Hey all. I’m having problems with the Smallest Common Multiple Bonfire. My code correctly calculates the LCM, but I don’t think that’s what they are really asking for. Can someone clarify?
Joe Balsamo
@Joe-Balsamo
Jun 28 2015 11:58
Never mind, I figured it out…missed the word: RANGE ;)
JMitnik
@JMitnik
Jun 28 2015 12:18
Are we supposed to think of our own Algorithm for Bonfire: Smallest Common Multiple? In terms of actually calculating all the multiples equal to one another?
Nathan Dimitriades
@nathandim
Jun 28 2015 12:48
I'm actually confused: Doesn't it ask for LCM or am I missing something?
because they're linking to https://www.mathsisfun.com/least-common-multiple.html and according to this method, LCM of 1, 5 should be 5 not 60 like the test asserts
@JMitnik
JMitnik
@JMitnik
Jun 28 2015 12:50
@nathandim it refers to the lcm of 1 to 5, meaning (1,2,3,4,5)
Nathan Dimitriades
@nathandim
Jun 28 2015 12:51
yes, even wolfram gives me 5
JMitnik
@JMitnik
Jun 28 2015 12:51
2 is not a common multiple of 5, but it is of 60
same for 3
and same for 4
Don't look at [1,5] as only 1 and 5, but as a range from START to FINISH
Nathan Dimitriades
@nathandim
Jun 28 2015 12:52
but when I'm running the program it says expect(smallestCommons([1,5])).to.equal(60);expected [ 1, 5 ] to equal 60
why should it be 60 when wolfram gives me 5?
JMitnik
@JMitnik
Jun 28 2015 12:52
What do you insert into wolfram alpha?
Nathan Dimitriades
@nathandim
Jun 28 2015 12:52
LCM(1, 5)
JMitnik
@JMitnik
Jun 28 2015 12:52
Right, Wolfram alpha takes the LCM of 1 and 5
But again, this assignment is about the lcm of ALL THE NUMBERS BETWEEN 1 AND 5
including 1 and 5 as well
Nathan Dimitriades
@nathandim
Jun 28 2015 12:53
ah
well thank you for the help
gotta have lunch and get back to it later
brain pls stop thinking programming I'm trying to eat
JMitnik
@JMitnik
Jun 28 2015 13:02
You're welcome
On another note, why should one use Array.some in the Finders Keepers bonfire, when .some doesn't return the index?
Moisés Man
@moigithub
Jun 28 2015 13:30

morning....
im doin this.. but seems something is wrong.. package installed,, but tutorial doesnt seems to start....
http://www.freecodecamp.com/challenges/waypoint-manage-packages-with-npm
Run this command: npm install how-to-npm -g
Now start this tutorial by running npm install how-to-npm@2.0.0.

... wonder IF its the same as ... this link i gooogled
https://libraries.io/npm/how-to-npm

i cannot figure out how to work with this -> add(2)(3)
Karan Joisher
@karanjoisher
Jun 28 2015 13:53
thanks @moigithub
Karan Joisher
@karanjoisher
Jun 28 2015 14:00
how do i access (3) in that function
JMitnik
@JMitnik
Jun 28 2015 14:26
Is the 'Convert HTML Entities' bonfire working well already?
Karan Joisher
@karanjoisher
Jun 28 2015 14:27
no it has some bugs
skip it3
Karan Joisher
@karanjoisher
Jun 28 2015 14:34
ee.JPG
Karan Joisher
@karanjoisher
Jun 28 2015 14:40

'''
function add() {
if(arguments.length > 1){
var arr = Array.prototype.slice.call(arguments);
return arr.reduce(function(currentValue,previousValue){return currentValue + previousValue;});
}

function AndAdd(arr[0], y){
return arr[0] + y;
}
return AndAdd;
}

add(2,3);

'''

'''
function add() {
if(arguments.length > 1){
var arr = Array.prototype.slice.call(arguments);
return arr.reduce(function(currentValue,previousValue){return currentValue + previousValue;});
}
function AndAdd(arr[0], y){
return arr[0] + y;
}
return AndAdd;
}
add(2,3);
'''
function add() {
if(arguments.length > 1){
var arr = Array.prototype.slice.call(arguments);
return arr.reduce(function(currentValue,previousValue){return currentValue + previousValue;});
}
function AndAdd(arr[0], y){
return arr[0] + y;
}
return AndAdd;
}
add(2,3);

am getting errors as shown in above picture

please help

Niall Szalkai
@NiallSzalkai
Jun 28 2015 15:55
This message was deleted
This message was deleted
This message was deleted
This message was deleted
Can anyone help me understand why the second call returns false?
function palindrome(str) {
  var strReverse = str.split('').reverse().join('').replace(/[\,\.?\s]/g,"");
  if (strReverse === str) {
    return true;
  }
  else {
    return false;
  }
}

palindrome("eye");
palindrome("A man, a plan, a canal. Panama”);
Alyssa Alvarez
@AlysCole
Jun 28 2015 16:00
Remove the spaces, too.
Lightwaves
@Lightwaves
Jun 28 2015 16:01
he is removing the spaces
Nikola Čvorović
@cvorak
Jun 28 2015 16:01
@NiallSzalkai beecause lower and upper case letters are different
Alyssa Alvarez
@AlysCole
Jun 28 2015 16:01
Ah. didn't see that.
Lightwaves
@Lightwaves
Jun 28 2015 16:01
there is one other thng
Nikola Čvorović
@cvorak
Jun 28 2015 16:01
you have to .toLowerCase
it
:)
Lightwaves
@Lightwaves
Jun 28 2015 16:01
look at what your comparing against in the second example
Niall Szalkai
@NiallSzalkai
Jun 28 2015 16:02
Ohh thanks :)
Nikola Čvorović
@cvorak
Jun 28 2015 16:02
np
Niall Szalkai
@NiallSzalkai
Jun 28 2015 16:05
Still not working for me, I feel I'm doing something wrong :P
var strReverse = str.split('').reverse().join('').replace(/[\,\.?\s]/g,"").toLowerCase();
  if (strReverse === str) {
Lightwaves
@Lightwaves
Jun 28 2015 16:05
haha
I was going to post it
"amanaplanacanalpanama" === "A man, a plan, a canal. Panama”
look at what your comparing against closely in the second example
Niall Szalkai
@NiallSzalkai
Jun 28 2015 16:06
Jesus christ what am I doing
This is what 3 hours sleep gets me >.< thanks man
Lightwaves
@Lightwaves
Jun 28 2015 16:06
np
Niall Szalkai
@NiallSzalkai
Jun 28 2015 16:08
All done, thanks man been stuck on that one a while
Lightwaves
@Lightwaves
Jun 28 2015 16:25
I'm stuck on 7 of them
Terrence
@terrencechambers
Jun 28 2015 16:31
I know what that is like. I have to force myself to walk away and sleep and come back the next day so I can figure it out.
Lightwaves
@Lightwaves
Jun 28 2015 16:31
Once you start dreaming in code it's all over....
Moisés Man
@moigithub
Jun 28 2015 16:53
thats why console.log( variable ) always helps....
Grace
@dogbot101
Jun 28 2015 17:03
Anyone have tips for the fibonacci bonfire?
Tammy
@howetc
Jun 28 2015 17:04
@dwilbank68 thank you muchly!
Lightwaves
@Lightwaves
Jun 28 2015 17:05
@dogbot101 break the problem up into steps
like first get a list of the fibonacci numbers then get only the odd ones, finally add all the odd ones to get our final answer.
Grace
@dogbot101
Jun 28 2015 17:20
Thanks @Lightwaves . I was thinking of using a for loop that has variables for a placeholder of the sum of the previous numbers that changes and then maybe pushing the answer into an array and then maybe filtering the array
cblupodev
@cblupodev
Jun 28 2015 18:03
I don't understand what Convert HTML Entities is asking me to do [freecodecamp.com]
The input and output look exactly the same [i.imgur.com]
Grace
@dogbot101
Jun 28 2015 18:04
I heard the Convert HTML Entitites Bonfire had a bug and heard its best to skip it for now...
cblupodev
@cblupodev
Jun 28 2015 18:05
@dogbot101 Ah. okay. Thanks
Terrell Vest
@MirPresT
Jun 28 2015 18:27
Kinda stuck on the Map the Debris Bonfire ... I am not sure what formula to use. I checked the wikipedia and couldnt figure out what formula would work given the values we are given. Some guidance would be much appreciated.
Rasheed Bustamam
@abustamam
Jun 28 2015 18:34
@MirPresT that one is tough
The formula you want is something like pi * (a ^ 3 / GM)
lemme double check
Haha that was totally wrong
2*Math.PI*Math.sqrt(a^3/GM)
Terrell Vest
@MirPresT
Jun 28 2015 18:36
close ok yea is the a the radius of the earth plus the avg altitude?
Rasheed Bustamam
@abustamam
Jun 28 2015 18:36
you got it!
Terrell Vest
@MirPresT
Jun 28 2015 18:36
ok i got it then . thanks. Ill test it .
Rasheed Bustamam
@abustamam
Jun 28 2015 18:36
:) its more math than programming for that prob
Lightwaves
@Lightwaves
Jun 28 2015 18:36
I'm stuck on pairwise I can get all combinations for the element indexes that add up to arg but I can't figure out how to get the smallest sum
Terrell Vest
@MirPresT
Jun 28 2015 18:36
very true.
Nathan, the one I believe created the challenge is a big proponent for math it seems
Rasheed Bustamam
@abustamam
Jun 28 2015 18:37
@Lightwaves what's your code look like?
I see. I like problems like that one because I learn about things that aren't programming.
Lightwaves
@Lightwaves
Jun 28 2015 18:40
function pairwise(arr, arg) {
  indexes = [];
  smallestsum = [];
  arr.forEach(function(element, index, array){
    for(var i = 1+index; i < array.length; i++){
      if (element + array[i] === arg){
        indexes.push(index);
        indexes.push(i);
        break;
      }
    }

  });
  if (indexes.length === 0){
    return 0;
  }
  else{
    return 0;







  }
}
the else is a stub so don't don't worry about the return 0 there
lol
pretty much for the indexes probally should have named that indices lol
Rasheed Bustamam
@abustamam
Jun 28 2015 18:43
lol, this is coding, not grammar :P
It's interesting that you're using the foreach method
but within it you're using a for loop
Lightwaves
@Lightwaves
Jun 28 2015 18:44
haha that is rather weird!
Rasheed Bustamam
@abustamam
Jun 28 2015 18:44
That actually won't work in this case because the first loop traverses the entire loop
which means at the last element, index = arr.length -1
so the inner loop will have for (var i = arr.length) which is out of bounds
that being said, keep in mind each element can only be used in a pair once
so let's say we had [0, 0, 0, 1, 1] ...
and args is 1
Lightwaves
@Lightwaves
Jun 28 2015 18:46
at the last element because i is 1+index
I'm pretty sure the for loop just never runs
so it evaluates false and does nothing
the previous iteration would push index and i are pushed
Rasheed Bustamam
@abustamam
Jun 28 2015 18:47
thats true, because then i !< length
your code would return true for indices 0 and 3, as well as for 1 and 3... so the third index (the first one) would be used twice
Lightwaves
@Lightwaves
Jun 28 2015 18:48
so it gets all of the elements in the array that are equal to arg
Rasheed Bustamam
@abustamam
Jun 28 2015 18:48
can you think of a way that would ensure the numbers don't get doubled-up?
Lightwaves
@Lightwaves
Jun 28 2015 18:48
They aren't being doubled up either i'll show you some of my outputs for indices
for pairwise([1, 4, 2, 3, 0, 5], 7) indices are [1, 3, 2, 5]
Rasheed Bustamam
@abustamam
Jun 28 2015 18:50
what about for pairwise([0,0,0,1,1], 1)?
Lightwaves
@Lightwaves
Jun 28 2015 18:51
pairwise([0,0,0,0,1,1], 1);
the indices are [0,4,1,4,2,4,3,4]
I did it out by hand and they in fact add up to 1
Moisés Man
@moigithub
Jun 28 2015 18:51
u have repeated indices... lot of 4
Rasheed Bustamam
@abustamam
Jun 28 2015 18:51
yeah, see how you're getting doubled up?
you sohuldn't have 4 there more than once
you should get [0,4,1,5] and done
Lightwaves
@Lightwaves
Jun 28 2015 18:52
That's my issue I can't think of a way to transform that to 0,4,1,5
Moisés Man
@moigithub
Jun 28 2015 18:52
u can do 2 things.. i gues... check if already exist before push.... OR filter uniques
Rasheed Bustamam
@abustamam
Jun 28 2015 18:53
so you need to figure out a way to tell your program that an element has already been used up
Lightwaves
@Lightwaves
Jun 28 2015 18:53
I tried filter uniques that quite didn't work
I'll keep thinking of things
Rasheed Bustamam
@abustamam
Jun 28 2015 18:54
you can check if index exists before push, like @moigithub said
Moisés Man
@moigithub
Jun 28 2015 19:04
npm if i already added an user... with npm adduser
but.. when i try to npm publish
it keep telling me
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`
what im doin wrong
Lightwaves
@Lightwaves
Jun 28 2015 19:09
@abustamam and @moigithub Thank you so much for the help!
function pairwise(arr, arg) {
  indexes = [];
  smallestsum = [];
  arr.forEach(function(element, index, array){
    for(var i = 1+index; i < array.length; i++){
      if (element + array[i] === arg){
        if (indexes.indexOf(index) == -1 && indexes.indexOf(i) == -1){
        indexes.push(index);
        indexes.push(i);
        break;
        }
      }
    }

  });
  if (indexes.length === 0){
    return 0;
  }
  else{
    return indexes.reduce(function(x,y){
      return x+y;
    });   






  }
}










pairwise([1,1,1], 2);
this in fact passed
I probably should stop being silly and use a double for loop instead of forEach for lol
It's just how I put the problem together in my head
Rasheed Bustamam
@abustamam
Jun 28 2015 19:14
yeah
you also didn't use the smallest sum array :P
Tammy
@howetc
Jun 28 2015 19:14
halp! i have code that should generate what i want but wasn't, trying to figure out if the waypoint is the issue or i. using !imporant, I want font in h2 to be red. I was linked earlier to a very helpful page, and I did input
```
h2 {
.urgently-red (
h2 {
.urgently-red (
color: red !important)
}
did i make a mistake by creating a class?
Rasheed Bustamam
@abustamam
Jun 28 2015 19:15
also, one more optimization trick... instead of returning indexes.reduce, you can actually keep a running total and instead of adding indices to an array, you can just add them up on the spot
@howetc it seems like you have parents () instead of curly braces {}
Tammy
@howetc
Jun 28 2015 19:16
this is what i have :
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
<style>

 h2 (
  .urgently-red {
    color: red !important
  }
  .blue-text {
    color: blue;     
  }
  )

  p (
  {font-size:16px;
  font-family: Lobster Monospace; 
  }
 )

</style>

<h2 class='blue-text urgently-red'> CatPhotoApp </h2>

<p class='red-text'>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p class='red-text'>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
@abustamam so it should be
```
h2 {
.urgently-red (
color: red !important)
}
?
Moisés Man
@moigithub
Jun 28 2015 19:20
<style>
htmltags {
   // styles
}

.classname {
  //styles
}

#idname {
 // styles
}

htmltag2    ,
 .classname2     , 
 #idname2 {
   // styles
}
</style>
Tammy
@howetc
Jun 28 2015 19:21
when i utilize brackets instead of the braces i get an error.
Moisés Man
@moigithub
Jun 28 2015 19:23
how ?
Tammy
@howetc
Jun 28 2015 19:25
i misspoke - i shouldn't say error - it's highlighted in red and the font that i've selected is not used, nor does it show up in red
Moisés Man
@moigithub
Jun 28 2015 19:26
copy/paste code.. or take screenshot n link the image plz :)
otherwise will be hard to "guess"
Tammy
@howetc
Jun 28 2015 19:26
i posted it above
Lightwaves
@Lightwaves
Jun 28 2015 19:27
I found something rather interesting on reduce and summing an array of values.
Tammy
@howetc
Jun 28 2015 19:27
!! :satisfied: as soon as you said that i went back to look at the code i figured it out
thanks @moigithub
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
<style>
  .red-text {
    color: red;
  }
  .urgently-red {
    color: red !important;
  }
  .blue-text {
    color:blue
  }

  h2 {
    font-family: Lobster, Monospace;
  }

  p {
    font-size: 16px;
    font-family: Monospace;
  }
</style>

<h2 class='red-text blue-text urgently-red'>CatPhotoApp</h2>

<p class='red-text'>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p class='red-text'>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
i'd miss-typed the class blue-text which created an issue when i tried to assign in to h2
Mario Mitchell
@undergroundfx
Jun 28 2015 19:42
Just created a timer to use on my Pomodoro Clock. I've got it to increment in relation to the amount of total time but can't get it to build from the bottom up. I must be missing something simple..
Stjepan Mazalovic
@stjema
Jun 28 2015 19:45
fatal error C1083: Cannot open include file: 'cs50.h': No such file or directory
library50-c-5\cs50.c(68): error C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\stdio.h(304) : see declaration of 'sscanf'
i do a cs50x course
and i'm using visual studio community. i pasted the cs50.c and cs50.h in the source files https://courses.edx.org/courses/HarvardX/CS50x3/2015/courseware/b2f7d86728354866a2c4438e76c3ec55/1c9bf196aa814998813103227b398bca/ the staff is using gedit on linux vm
Steven Leiva
@StevenXL
Jun 28 2015 19:56
Hi everyone.
I am working on the TwitchTV API zipline.
I am successfully getting the data that I need from the API.
Now I am working on adding that data to the DOM.
Rasheed Bustamam
@abustamam
Jun 28 2015 19:57
@undergroundfx you want it to go to green from the bottom?
Steven Leiva
@StevenXL
Jun 28 2015 19:57
Can someone help me figure out why that part is not working.
My code can be found here.
Rasheed Bustamam
@abustamam
Jun 28 2015 19:58
what seems to be going wrong @StevenXL ?
Steven Leiva
@StevenXL
Jun 28 2015 19:59
@abustamam Well, I am getting the data from the TwitchTV API. Then, I created a function to add that data to the DOM using jQuery. In my HTML file, I have an empty div, like so:
<div class="user-list">
</div>
And in my script file (the one that I linked to in the gist), I want to add the information form the API to that element, using $(".user-list").append(nodeStructure);
You can see how I built nodeStructure in the gist.
I test the function by calling it - allButton(); - although eventually I plan to make that function a trigger when the actual button the website is clicked.
Rasheed Bustamam
@abustamam
Jun 28 2015 20:02
and when you click allbutton nothing happens?
my guess is that things might be running async
Steven Leiva
@StevenXL
Jun 28 2015 20:03
@abustamam there is no button yet. I call it manually using the code on Line 71 of the gist.
@abustamam ah yes. That is right.
I've ran into this problem before, wondering why my arrays where empty.
Rasheed Bustamam
@abustamam
Jun 28 2015 20:03
or rather sync
yeah
Steven Leiva
@StevenXL
Jun 28 2015 20:03
How can I fix this?
Rasheed Bustamam
@abustamam
Jun 28 2015 20:03
do you know how to use async?
Steven Leiva
@StevenXL
Jun 28 2015 20:03
I don't think so.
Rasheed Bustamam
@abustamam
Jun 28 2015 20:04
I'm not there yet so I don't know if you've learned this yet (I'm still going through functional programming)
Steven Leiva
@StevenXL
Jun 28 2015 20:04
@abustamam Nope. That's not something they touch upon. I guess it's up to use to learn it.
Rasheed Bustamam
@abustamam
Jun 28 2015 20:04
But there are callbacks that you can run
Steven Leiva
@StevenXL
Jun 28 2015 20:04
But I know that getJSON is AJAX, so it works asynchroniously.
Moisés Man
@moigithub
Jun 28 2015 20:04
add a button to ur html.. and $("#thebutton").click(function(){ allButton(); });
wait few seconds.. and click the button
Steven Leiva
@StevenXL
Jun 28 2015 20:04
@moigithub OK I will do that.
Moisés Man
@moigithub
Jun 28 2015 20:05
at some point data will arrive.. and it will populate ur array :)
cuz async
Steven Leiva
@StevenXL
Jun 28 2015 20:05
My mind is obviously not used to thinking in "async" mode. I have little programming experience besides stuff like CodeAcademy, etc.
And I've never had to deal with situations where the code doesn't run top down.
brb, going to add the button to my html.
adcor
@adcor
Jun 28 2015 20:06
Hey all, I have a question for the Where Do I Belong bonfire. I can't get the function to return the original array with the newly populated data.
function where(arr, num) {
  var arr1 = arr.sort();
  for(var i = 0; i < arr.length; i++){
     if(num > arr1[i] && num < arr1[i+1]){ 
         return arr1.splice(i+1, 0, num);

     } 
  }
  var arra = arr;
  console.log(arr1);
}
Moisés Man
@moigithub
Jun 28 2015 20:06
but if u immediatelly call allButton most chances is it will not show all or any
Steven Leiva
@StevenXL
Jun 28 2015 20:08
@moigithub @abustamam it worked!
Wow - this is exciting stuff.
It looks like crap, but nothing a little CSS can't fix!!
haha - I also have to make sure that the list is cleared every time the button is pressed, otherwise I keep adding to it.
Tony Keovongphet
@TSKeo
Jun 28 2015 20:11
function repeat(str, num) {
  if (num < 0) return "";
  return Array(num + 1).join(str);
}

repeat('abc', 3);
Can someone explain to me what line 3 does or point me to a resource that will help? I looked through all Array docs, but still don't know how it works.
Moisés Man
@moigithub
Jun 28 2015 20:11
what i did.. was "insert" all those html.. on done callback.. so when data arrive it update the webpage
Mona Jalal
@monajalal
Jun 28 2015 20:11
what's wrong with this?

<style>
.red-text {
color: red;
}
p{font-size:16px;}
</style>

<h2 class='red-text'>CatPhotoApp</h2>

<p class='red-text'>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p>
Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.
</p>

Moisés Man
@moigithub
Jun 28 2015 20:12
ofc sometimes... "freecodecamp" user.. was on top.. and sometime was at bottom... cuz server lag delay probably, sometimes takes more time to "answer" and sometimes is "faster"
Tony Keovongphet
@TSKeo
Jun 28 2015 20:14
@lamiastella, everything looks fine what is the error?
Steven Leiva
@StevenXL
Jun 28 2015 20:15
@abustamam @moigithub thank you so much for your help.
Moisés Man
@moigithub
Jun 28 2015 20:16
This message was deleted
Tom DeFrank
@TomDeFrank
Jun 28 2015 20:18
is convert HTML Entities bonfire broken?
or am i?
:)
Moisés Man
@moigithub
Jun 28 2015 20:19
@adcor on that exercise u need to return the INDEX
@TomDeFrank yep is buggy
Steven Leiva
@StevenXL
Jun 28 2015 20:19
there is so much that can be refactored here, it's not even funny, but guys - it is working!
adcor
@adcor
Jun 28 2015 20:20
@moigithub yeah, I know, as part of that I was going to first get back the now modified array and then use indexOf
Tom DeFrank
@TomDeFrank
Jun 28 2015 20:20
@moigithub ok cool thanks
Moisés Man
@moigithub
Jun 28 2015 20:20
@adcor why indexOf.. if u already have var i
Alex Khomenko
@Clarity-89
Jun 28 2015 20:22
has anyone done Pairwise bonfire?
adcor
@adcor
Jun 28 2015 20:23
@moigithub interesting, yeah, sometimes my thinking is a bit convoluted, but regardless, would still like to know why I couldn't get the modified array back
Moisés Man
@moigithub
Jun 28 2015 20:24
@Clarity-89 u need to return AT or GC in this format ['A', 'T']
if u get an A u return T.. if u get T u return A
it's this one
Moisés Man
@moigithub
Jun 28 2015 20:28
splice modify the array, if u wanna return the original.. u need to make a copy first... and NO a = b.. but a = b.slice()
he splice() method adds/removes items to/from an array, and returns the removed item(s).
@adcor
@Clarity-89 ahh.. lemme check
@Clarity-89 pairwise([1,4,2,3,0,5], 7);
u need to return the sum of indices whos values add up to second parameter (7 in that example) @Clarity-89
@Clarity-89 so in that example... 4+3 = 7 and 2+5 = 7.. their indices are ... 1+2+3+5 = 11
Alex Khomenko
@Clarity-89
Jun 28 2015 20:31
I have problems with pairwise([1,1,1], 2)
and pairwise([0, 0, 0, 0, 1, 1], 1)
Moisés Man
@moigithub
Jun 28 2015 20:31
and u cant reuse the indices if u already used the values
so.. 1+1 = 2.. (indices 0 and 1) both used... only 1 (index 3) left
Alex Khomenko
@Clarity-89
Jun 28 2015 20:32
yeah, so is it possible to solve it using Array.prototype.reduce() only?
Moisés Man
@moigithub
Jun 28 2015 20:33
not sure if possible.. but i used 2 nested loops :)
Alex Khomenko
@Clarity-89
Jun 28 2015 20:33
lol
Moisés Man
@moigithub
Jun 28 2015 20:34
first understand the problem.. make it work.. finally refactor :)
Alex Khomenko
@Clarity-89
Jun 28 2015 20:34
I had a 30-line solution refactored into 15 and still doesn't work
Moisés Man
@moigithub
Jun 28 2015 20:34
all my code is ugly.. im skiping the refactorthing :)
Alex Khomenko
@Clarity-89
Jun 28 2015 20:34
yeah, have to think again
hah, alright
Niall Szalkai
@NiallSzalkai
Jun 28 2015 21:12
Alright guys I feel as if I cheated this one by not doing it the way the bonfire is suggesting I do it. Did you guys do it in a different way?
function findLongestWord(str) {
  var strArray = str.split(" ");
  for (var i = 0; i < strArray.length; i++) {
    strArray[i] = strArray[i].length;
  }
  strArray.sort(function(a, b){return b-a});
  return strArray[0];
}

findLongestWord('The quick brown fox jumped over the lazy dog');
It would never return an actual word this way :worried:
Tony Keovongphet
@TSKeo
Jun 28 2015 21:42
Yeah.
function findLongestWord(str) {
  var longest = "";
  var arr = str.split(" ");
  for (var i = 0; i < arr.length; i++){
    if (arr[i].length > longest.length) {
      longest = arr[i];
    }
  }
  return longest.length;
}

findLongestWord('The quick brown fox jumped over the lazy dog');
sowpat
@sowpat
Jun 28 2015 21:43
First i declared a variable called max and set it equal to zero. I split the string and saved that into an array, then i looped through the array and compared the length of each element to max, if the element's length was greater than max i would set max equal to the length of that element. i then returned max. basically what TSKeo did
Lightwaves
@Lightwaves
Jun 28 2015 21:57
I need to go back and refactor like all my solutions
lol
some are elegent some are just plain ugly
function findLongestWord(str) {
  str = str.split(" ");
  var newArr = str.map(function(x){
    return x.length;
  });
  return Math.max.apply(null, newArr);

}

findLongestWord('The quick brown fox jumped over the lazy dog');
My line of thinking was get the length of each word then find the biggest so it originally lead to a map reduce solution but I changed it to Map and apply the max
Lightwaves
@Lightwaves
Jun 28 2015 22:03
I've been working on learning functional programming type of thinking so most of my solutions have been using map, reduce, apply,etc. worst case if a solution is correct but slow you can always refactor it procedurally.
for speed
Tony Keovongphet
@TSKeo
Jun 28 2015 22:11
That's awesome.