These are chat archives for FreeCodeCamp/Help

5th
Mar 2015
Suzanne Atkinson
@AdventureBear
Mar 05 2015 02:48 UTC
does anyone find this documentation style confusing?
arr.find(callback[, thisArg])
Darryl Dixon - Piece Digital
@piecedigital
Mar 05 2015 02:48 UTC
Kind of.
Suzanne Atkinson
@AdventureBear
Mar 05 2015 02:49 UTC
I'm still uncertain what a callback is. I have used it, and can plug and play an example but when reading the description it' snot intuitive
Darryl Dixon - Piece Digital
@piecedigital
Mar 05 2015 02:49 UTC
call back is the callback function
Nathan
@terakilobyte
Mar 05 2015 02:49 UTC
a callback is just a function you want it to execute
think of using map or filter on an array
function square(num) {
  return num * num;
}
[1, 2, 3].map(square);
often times you see it like this
[1, 2, 3].map(function(elem) {
  return elem * elem;
});
Suzanne Atkinson
@AdventureBear
Mar 05 2015 02:53 UTC
so in that example 'square' is the callback function?
Nathan
@terakilobyte
Mar 05 2015 02:53 UTC
the documentation style is actually showing you what is required and what is optional
Suzanne Atkinson
@AdventureBear
Mar 05 2015 02:53 UTC
and in the 2nd example you've written it out as a shorthand way
Cristián Berríos
@crisberrios
Mar 05 2015 02:53 UTC
but in the context of node, you could say it sets the point of return of an async function
Nathan
@terakilobyte
Mar 05 2015 02:53 UTC
remember in js functions can take a lot of arguments
Cristián Berríos
@crisberrios
Mar 05 2015 02:54 UTC
look at this example:
Suzanne Atkinson
@AdventureBear
Mar 05 2015 02:54 UTC
I know! drives me crazy. :) I know I just need more practice but I still feel like I'm looking everything up everytime for the bonfires.
Nathan
@terakilobyte
Mar 05 2015 02:54 UTC
so arr.find(callback[, thisArg]) is saying thisArg is an optional
Suzanne Atkinson
@AdventureBear
Mar 05 2015 02:54 UTC
simple loops and stuff I'm finally good at.
Nathan
@terakilobyte
Mar 05 2015 02:54 UTC
you don’t have to define it
but, callback isn’t inside the brackets, so it’s not optional. You must supply that argument to find
Suzanne Atkinson
@AdventureBear
Mar 05 2015 02:55 UTC
right, then it's not intuitive what 'thisArg' is good for. so does callback HAVE to be a function then in that example ?
Nathan
@terakilobyte
Mar 05 2015 02:55 UTC
yes
Cristián Berríos
@crisberrios
Mar 05 2015 02:55 UTC
function async () {
doSomethingAsync();
console.log("async done!");
}

console.log("1");
async();
console.log("3");
1
3
async done!
Nathan
@terakilobyte
Mar 05 2015 02:56 UTC
often times the “thisArg” is something you provide to bind this to
Suzanne Atkinson
@AdventureBear
Mar 05 2015 02:56 UTC
which means it should occur inside some other structure?
Nathan
@terakilobyte
Mar 05 2015 02:57 UTC
it doesn’t have to
Cristián Berríos
@crisberrios
Mar 05 2015 02:57 UTC
and now this example:
function async () {
doSomethingAsync();
return true;
}

console.log("1");
console.log(async());
console.log("3");
Suzanne Atkinson
@AdventureBear
Mar 05 2015 02:57 UTC
ok
Nathan
@terakilobyte
Mar 05 2015 02:57 UTC
in asynchronous programming you’ll usually define the callback external to the method call you are making to trigger something
Cristián Berríos
@crisberrios
Mar 05 2015 02:58 UTC
what do you think will be the output of that?
Nathan
@terakilobyte
Mar 05 2015 02:58 UTC
when using things like find, map, reduce, filter
Suzanne Atkinson
@AdventureBear
Mar 05 2015 02:58 UTC
1 true 3
?
Nathan
@terakilobyte
Mar 05 2015 02:58 UTC
you are safe to just write the callback as an argument
Cristián Berríos
@crisberrios
Mar 05 2015 02:59 UTC
nope
it will print
1 undefined 3
Suzanne Atkinson
@AdventureBear
Mar 05 2015 02:59 UTC
@terakilobyte i am still not 100% comfortable with examples of asycn programming to know how what you just said fits in. I know what it is but just need more practice.
Cristián Berríos
@crisberrios
Mar 05 2015 02:59 UTC
hmmm
the example is bad
Suzanne Atkinson
@AdventureBear
Mar 05 2015 02:59 UTC
why?
lol
why directed @ @crisberrios
Cristián Berríos
@crisberrios
Mar 05 2015 02:59 UTC
it should be something like this
xD
Nathan
@terakilobyte
Mar 05 2015 03:00 UTC
@AdventureBear it comes with practice
and, a lot of the problems with callbacks and their ordering is resolved with promises
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:00 UTC
sounds like a good relationship! :) flowers, dinners, promises...
Nathan
@terakilobyte
Mar 05 2015 03:00 UTC
inorite :)
Cristián Berríos
@crisberrios
Mar 05 2015 03:01 UTC
function async () {
return doSomethingAsync(); // function returns true;
}
now it will print 1 undefined 3
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:01 UTC
@crisberrios so why the undefined?
I'm not clear what the connection is
Cristián Berríos
@crisberrios
Mar 05 2015 03:02 UTC
the thing with async functions
like reading from a database
or loading a file
is that they aren't instant
and JS doesn't wait for the result (unless you use a sync version of the function)
so, in this case you try to return a value from an async function
the function won't return a value until later on
and when it does
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:04 UTC
ahha! that makes complete sense (so far).
Cristián Berríos
@crisberrios
Mar 05 2015 03:04 UTC
there won't be anything to catch that value
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:04 UTC
there was a nodeschool challenge along those lines
Cristián Berríos
@crisberrios
Mar 05 2015 03:04 UTC
so, instead of using return
as in a normal function
you call another function passed as a callback
and pass the return value
in some functions the argument is named as callback
in others is called done
for the sake of convention
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:07 UTC
hmm. I need to think about that. so how would the output of your mini code above be different in a properly executed asynch callback function?
or would the value just be caught and able to be used at some point down the line in theprogram?
Nathan
@terakilobyte
Mar 05 2015 03:08 UTC
function doSomethingAsync() {
  return setTimeout(function() {
    console.log('hi');
  }, 1000);
}

function async() {
  return doSomethingAsync();
}

(function() {
  console.log(1);
  async();
  console.log(3);
})();
open a new browser window and put that in your console
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:08 UTC
ok, i'm going to guess first what it might do
i'm going to guess 1 undefined 3, then a second later print hi. and not 1 hi 3
Nathan
@terakilobyte
Mar 05 2015 03:09 UTC
nope
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:10 UTC
that's what it did I think!
almost
1
3
undfined
then "hi"
Nathan
@terakilobyte
Mar 05 2015 03:10 UTC
yep
why undefined?
points if you can guess ;)
Priscilla P. Wood
@RailsGirl
Mar 05 2015 03:12 UTC
oh and now I’m waiting for her reply
Nathan
@terakilobyte
Mar 05 2015 03:13 UTC
I’ll give you a small hint if you want
in the form of code to run and reason about
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:14 UTC
hang on...
Nathan
@terakilobyte
Mar 05 2015 03:15 UTC
yes’m
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:16 UTC
ok well one thing I'm not clear on that may not be related is why the last function, the one that runs, is surrounded by () for no good reason!
Nathan
@terakilobyte
Mar 05 2015 03:16 UTC
it’s an iife
immedately invoked function expression
@RailsGirl any guesses of your own?
why undefined?
Ryan Malm
@Rybar
Mar 05 2015 03:19 UTC
ooh! ooh! pick me! ;)
:hand:
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:19 UTC
I give up on the undefined for now. maybe it's expecting a return since it's called and doesn't know that the returnn is coming later?
Nathan
@terakilobyte
Mar 05 2015 03:20 UTC
ok ok
first the hint
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:20 UTC
haha @Rybar
Nathan
@terakilobyte
Mar 05 2015 03:20 UTC
function doSomethingAsync() {

    return setTimeout(function() {
      console.log('hi');
    }, 1000);
  }

function async() {
  return doSomethingAsync();
}

(function() {
  console.log(1);
  async();
  console.log(3);
  return 'definitely defined now';
})();
now, @Rybar for the answer!
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:20 UTC
hmm.
weird
i don't see any difference aside from the obvoius return statement
oh...that's it?
Priscilla P. Wood
@RailsGirl
Mar 05 2015 03:21 UTC
Nope, I have no idea...
Nathan
@terakilobyte
Mar 05 2015 03:21 UTC
;)
Julie Myers
@BlueOceanView
Mar 05 2015 03:21 UTC
Here are a few notes about an IIFE:
///////////////////////////////////////////////////////////////////
/* Creating an Immediately Invoked Function Expression - Step by Step */
var newScope = function(a, b, c){
   var a, b, c; // these are local to this function.  
   return a + b + c; 
};
newScope(1,1,1); /* 3 --->  Variables a, b, c are contained inside the function's scope.  They can not be
                             accessed from the global scope. */

/* A different way to get the function to run is to create it without a name and than type in the 
     syntax so it runs immediately.  Since the function does not have a name I can NOT call it like newScope(); */
/* (1) Create a function without a name: */
function(a, b, c){
    var a, b, c; // these are local to this function.
    return a+b+c;   
 }

 /* (2) Put parenthesis around that function: */
 (function(a, b, c){
    var a, b, c; //these are local to this fucntion.
    return a+b+c;   
}) /* ---> these parenthesis do NOT call the function. They are acting like parenthesis in a math problem, such
       that what is inside the parenthesis get evaluated. They evaluate to a function object. */ 

/* (3) Since the parenthesis in 2 above evaluate to a function object, I can now call the function by putting
       another set of parenthesis at the end. */
(function(a, b, c){
    var a, b, c; //these are local to this fucntion.
    return a+b+c;   
})(); /* ---> This last pair of parenthesis will call the function. They are function execution parenthesis
               meaning they can take arguments like any other function call.*/

/* This is called an Immediately Invoked Function Expression.  It is how I create a private scope.  Since 
   it does not have a name there is no way for a name collision to happen with another script/function.
   Also, the variables are local/inside the function's scope so it will not leak out into the global space. */               
(function(a, b, c){
    var a, b, c; //these are local to this fucntion.
    return a+b+c;   
})();                  
///////////////////////////////////////////////////////////////////
Nathan
@terakilobyte
Mar 05 2015 03:22 UTC
so in the first example, the iife wasn’t returning anything, so the result of the expression was undefined
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:22 UTC
ha. wow. crazy. you guys are blowing my mind tonight.
the drugs help too.
Nathan
@terakilobyte
Mar 05 2015 03:22 UTC
returning from the iife does give a value
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:22 UTC
;)
Nathan
@terakilobyte
Mar 05 2015 03:22 UTC
now, if you pull them all out of the iife
function doSomethingAsync() {

    return setTimeout(function() {
      console.log('hi');
    }, 1000);
  }

function async() {
  return doSomethingAsync();
}

  console.log(1);
  async();
  console.log(3);
you will get 1, 3, undefined, ‘hi’
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:23 UTC
wait.
why the undefined in that case? because the asynch isn't being caught?
Nathan
@terakilobyte
Mar 05 2015 03:24 UTC
it is, and it executes
but it’s a whole other function
being run asynchronously
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:24 UTC
but it's returning something
Nathan
@terakilobyte
Mar 05 2015 03:25 UTC
so doSomethingAsync() itself doesn’t return a value really, it’s starting setting a function that’s being executed in by the engine somewhere else
Priscilla P. Wood
@RailsGirl
Mar 05 2015 03:25 UTC
Well people, that was interesting, I’m going to bed. Tomorrow more coding :) Goodnight
Nathan
@terakilobyte
Mar 05 2015 03:25 UTC
@RailsGirl have a good one
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:25 UTC
night @RailsGirl
Hmm...OK, i'm slowly cataching on.
Nathan
@terakilobyte
Mar 05 2015 03:25 UTC
here, watch this video...
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:25 UTC
so the function is being executed but there's no return value
right, that’s the easiest way to think about it
watch the video and it will become a lot more clear on just what is happening I think
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:27 UTC
OK I will.
And...this will help me with Mutations ? ;-)
I like his accent. It makes him automatically cute.
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 03:31 UTC
@terakilobyte thanks for the video
Ryan Malm
@Rybar
Mar 05 2015 03:31 UTC
I know what's going on, but I have a different related? question: Why does the browser console return undefined when inputting any function?
Julie Myers
@BlueOceanView
Mar 05 2015 03:34 UTC
Ohhh...I used to know the answer to that @Rybar.
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 03:36 UTC
"used to know" - lol
Julie Myers
@BlueOceanView
Mar 05 2015 03:37 UTC
:P I know. It's late...I tend to just babble.
Nathan
@terakilobyte
Mar 05 2015 03:37 UTC
typing just a function or really anything that doesn’t result in an expression will show undefined in the console
Andrew Corcoran
@corca
Mar 05 2015 03:37 UTC
I feel like I need to review all of the above….tomorrow.
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:38 UTC
you guys have been a great help, i'm going to get some shut eye. Well, beer eye, then shut eye. thanks
Nathan
@terakilobyte
Mar 05 2015 03:38 UTC
lol
Ryan Malm
@Rybar
Mar 05 2015 03:39 UTC
that makes sense
Nathan
@terakilobyte
Mar 05 2015 03:42 UTC
I do love javascript
so many little fun corners to explore
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 03:50 UTC
Hey here's a very nooby JS question
How do I iterate over an array of numbers and calculate the sum?
Darryl Dixon - Piece Digital
@piecedigital
Mar 05 2015 03:52 UTC
reduce
i think
Julie Myers
@BlueOceanView
Mar 05 2015 03:52 UTC
There is an array method that does that.
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:52 UTC
Ok, well this is just a mess. Hope it's good for a laugh for someone
Nathan
@terakilobyte
Mar 05 2015 03:52 UTC
reduce
Suzanne Atkinson
@AdventureBear
Mar 05 2015 03:52 UTC
function mutation(arr) {


  function isInElement(element,index,array) {
    var second = arr[1].split("");
    var found = true; 

    for (i=0;i<second.length; i++)
    {     
      if (element===second[i]){

      } else {
        found = false; 
      }


      return found; 
    }
  }

  result = arr[0].split("").find(isInElement);

  return result; 



}

mutation(['hello', 'hey']);
Nathan
@terakilobyte
Mar 05 2015 03:53 UTC
@AdventureBear well...
Nathan
@terakilobyte
Mar 05 2015 03:53 UTC
can I ask two questions?
@AmmarAliShah yes
Darryl Dixon - Piece Digital
@piecedigital
Mar 05 2015 03:54 UTC
Yes.
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 03:54 UTC
Oh okay I'll read that
thanks all!
:smile:
Nathan
@terakilobyte
Mar 05 2015 03:56 UTC
@AdventureBear does any mutation of the string ‘bead’ exist anywhere in ‘dabe’ ?
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 03:56 UTC
Whenever I read the MDN, it results in me googling a bunch of other stuff I have no idea about
Nathan
@terakilobyte
Mar 05 2015 03:56 UTC
that’s partly the point
@AdventureBear my follow up question is, does any mutation of the string ‘abde’ exist anywhere in ‘abde’ :)
Cristián Berríos
@crisberrios
Mar 05 2015 04:03 UTC
I think she went to slepe
sleep
@piecedigital were you able to solve no repeats?
Darryl Dixon - Piece Digital
@piecedigital
Mar 05 2015 04:04 UTC
@crisberrios No.
Cristián Berríos
@crisberrios
Mar 05 2015 04:05 UTC
where are you stuck?
Darryl Dixon - Piece Digital
@piecedigital
Mar 05 2015 04:05 UTC
At the beginning lol
Cristián Berríos
@crisberrios
Mar 05 2015 04:06 UTC
lol
Darryl Dixon - Piece Digital
@piecedigital
Mar 05 2015 04:06 UTC
I stopped the mathematical route and tried something else but idk how to do it
Cristián Berríos
@crisberrios
Mar 05 2015 04:06 UTC
I literally posted an algorithm for permutations in the chat when you were at it
which is the 1st part of the problem using permutations
Julie Myers
@BlueOceanView
Mar 05 2015 04:06 UTC
@crisberrios and @terakilobyte Would you guys use the module pattern in combo with an event like this:
document.getElementById('sendButton').addEventListener('click', function(){
     console.log(eventsTesting.name);
     eventsTesting.alert();
 }, false);

 var eventsTesting = (function(){
     var name="Snoopy Rules!";
     var alertMe = function(){
         alert("I am inside of the module");
     };
     return {
         name: name,
         alert: alertMe
     };
 })();
Cristián Berríos
@crisberrios
Mar 05 2015 04:06 UTC
I can give you a hint on math, but you also need permutations
Darryl Dixon - Piece Digital
@piecedigital
Mar 05 2015 04:06 UTC
@crisberrios I didn't see it.
Cristián Berríos
@crisberrios
Mar 05 2015 04:07 UTC
scroll up :P
does it work @BlueOceanView ? seems ok at first glance
Darryl Dixon - Piece Digital
@piecedigital
Mar 05 2015 04:09 UTC
idk what I'm supposed to do with this function permutate ( array) return [] + array.map ( function(item) return permutate(array minus the item) )
Nathan
@terakilobyte
Mar 05 2015 04:09 UTC
I don’t see why you’d need to export anything
you’re binding the functionality to the ‘sendbutton'
if you wanted to make it so it could be bound to any button then yes, and then pass the button in as an argument
Julie Myers
@BlueOceanView
Mar 05 2015 04:10 UTC
@crisberrios It does work. I just want to make sure I'm not developing bad coding practices.
Cristián Berríos
@crisberrios
Mar 05 2015 04:10 UTC
it's "pseudo" js... add a few curly braces and turn the words into functions and variables
Julie Myers
@BlueOceanView
Mar 05 2015 04:12 UTC
@terakilobyte So, for a single button just put the functionality inside of the addEventListener function?
I'm trying to keep as many things out of the global scope as possible. Hence, why I coded it out like I did.
Cristián Berríos
@crisberrios
Mar 05 2015 04:14 UTC
after being confident about events watch this video @BlueOceanView https://www.youtube.com/watch?v=gawmdhCNy-A
Nathan
@terakilobyte
Mar 05 2015 04:14 UTC
@BlueOceanView you could also use strict mode :)
Meta Hirschl
@MetaCoderHirschl
Mar 05 2015 04:14 UTC
@crisberrios thanks for video!
Julie Myers
@BlueOceanView
Mar 05 2015 04:15 UTC
@terakilobyte (imagine a face of horror :P ). I was told that strict mode causes to many issues, thus don't use it.
Cristián Berríos
@crisberrios
Mar 05 2015 04:15 UTC
always use strict
Nathan
@terakilobyte
Mar 05 2015 04:16 UTC
^
not using strict causes folly and misery
Cristián Berríos
@crisberrios
Mar 05 2015 04:18 UTC
and always use JSHint or ESlint and also JSCS
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 04:20 UTC
just one question
okay I was reading on reduce and I think I understand it
Nathan
@terakilobyte
Mar 05 2015 04:21 UTC
I’m geeking out to this video
very good reference @crisberrios , thanks
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 04:21 UTC
var total = [0, 1, 2, 3].reduce(function(a, b) {
  return a + b;
});
// total == 6
Nathan
@terakilobyte
Mar 05 2015 04:21 UTC
looks legit
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 04:21 UTC
QUESTION:what does a and b do here
as in do they hold separate values
Cristián Berríos
@crisberrios
Mar 05 2015 04:23 UTC
a works as an accumulator
so for the 1st iteration
it has no value
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 04:23 UTC
In a computer's central processing unit (CPU), an accumulator is a register in which intermediate arithmetic and logic results are stored.
Cristián Berríos
@crisberrios
Mar 05 2015 04:24 UTC
then it has a+b
then it has (a+b)+c
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 04:24 UTC
As soon as I opened the MDN, the first thing I googled
Cristián Berríos
@crisberrios
Mar 05 2015 04:24 UTC
good definition
is the same for this case
Nathan
@terakilobyte
Mar 05 2015 04:25 UTC
a and b can be thought of as left and right on a simple level
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 04:25 UTC
So if I wanted to add odd and even numbers separately, how would I do that?
I thought it would have something to do with this a and b
Nathan
@terakilobyte
Mar 05 2015 04:25 UTC
[1, 2, 3].reduce(function(a, b) { return a + b })
on first pass a is 1 and b is 2
it returns one value, 3 and that is stored where 1 and 2 used to be, if it’s easy to think of it like that
then 3 is the left side (that we got back), and 3 (from teh array) is the right side
it combines those and returns 6 where 3, 3 used to be
the array is then length 1, and it returns 6
as an exercise, I recommend you write your own reduce that operates just like that
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 04:28 UTC
Actually I needed to add that array for practice
that is why I asked
but it has levels
Nathan
@terakilobyte
Mar 05 2015 04:28 UTC
don’t worry about adding it as a prototype method, just something like
function ammarReduce(arr) {
…
}
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 04:29 UTC
  • (1) Create an array of numbers, iterate over them and calculate the sum.
  • (2) Do #1, but sum up the odd and even numbers separately.
  • Create a list of full names. Break them out into three lists: first, middle, and last names. Count the frequency of the names in each list.
I get how I can do the first one now, but the second one confuses me
Nathan
@terakilobyte
Mar 05 2015 04:30 UTC
if I had just cooked a big pot of spaghetti
and then wanted to drain the water, I’d use a strainer, right?
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 04:31 UTC
what?
I got the spaghetti part
what was that water thing?
Nathan
@terakilobyte
Mar 05 2015 04:31 UTC
right
what is the act of separating the water
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 04:32 UTC
I have no experience in cooking, just saying
Nathan
@terakilobyte
Mar 05 2015 04:32 UTC
filtering
you could filter the array first
then sum it up
Cristián Berríos
@crisberrios
Mar 05 2015 04:37 UTC
@AmmarAliShah lol, you have to learn how to cook to be a good coder
xD
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 04:38 UTC
@crisberrios lol
I can make 2-minute noodles
but that's about it
Cristián Berríos
@crisberrios
Mar 05 2015 04:38 UTC
I can cook better than I code
if that's worth something
Julie Myers
@BlueOceanView
Mar 05 2015 04:38 UTC
@crisberrios LOL! You sound like a pretty good coder to me.
@terakilobyte What is the steamroller bonfire all about? The instructions don't say much.
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 04:39 UTC
@crisberrios then you must be as good as Gordan Ramsay cause you're one heck of a coder
Cristián Berríos
@crisberrios
Mar 05 2015 04:40 UTC
nah, tell me that after I get a senior dev job somewhere in the future :P
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 04:41 UTC
@crisberrios why not go for a junior one right now?
Cristián Berríos
@crisberrios
Mar 05 2015 04:41 UTC
still need more portfolio
and more knowledge, and more practice
Nathan
@terakilobyte
Mar 05 2015 04:42 UTC
strangely
Cristián Berríos
@crisberrios
Mar 05 2015 04:42 UTC
I want to land a good job, in a good company, hopefully in a good country or remote
Tyler Haas
@tylerthehaas
Mar 05 2015 04:42 UTC
I'm having trouble with the steamroller bonfire...anyone interested in getting me pointed in the right direction
Nathan
@terakilobyte
Mar 05 2015 04:42 UTC
I’m also a much better cook than coder
Tyler Haas
@tylerthehaas
Mar 05 2015 04:42 UTC
?
AmmarAliShah @AmmarAliShah has decided to learn to cook now
Tyler Haas
@tylerthehaas
Mar 05 2015 04:42 UTC
right now I am just having a hard time dealing with the varying levels of nesting
Julie Myers
@BlueOceanView
Mar 05 2015 04:42 UTC
@haasDev Are there any array methods that would take multiple arrays and combine them into one array?
Cristián Berríos
@crisberrios
Mar 05 2015 04:43 UTC
lol
Julie Myers
@BlueOceanView
Mar 05 2015 04:43 UTC
How do you turn off the video?
Tyler Haas
@tylerthehaas
Mar 05 2015 04:43 UTC
there are 2 concat and reduce but I don't know how to get at the ones that are 3 or 4 layers deep with those
Nathan
@terakilobyte
Mar 05 2015 04:44 UTC
above it you’ll see a little icon to close it
next to the timestamp of the message
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 04:44 UTC
it appears on hover
Julie Myers
@BlueOceanView
Mar 05 2015 04:44 UTC
@terakilobyte Thank you! getting annoying.
Nathan
@terakilobyte
Mar 05 2015 04:44 UTC
yeah, sorry. It is the best gif to represent that feeling though
Julie Myers
@BlueOceanView
Mar 05 2015 04:45 UTC
LOL! I hear ya.
Cristián Berríos
@crisberrios
Mar 05 2015 04:45 UTC
@haasDev seems a good case to use a recursive function + iterators
or the cheat forbidden version
Julie Myers
@BlueOceanView
Mar 05 2015 04:45 UTC
@haasDev I'll do a google search and see what I find. I don't know either.
Nathan
@terakilobyte
Mar 05 2015 04:45 UTC
I want to go have a lot of beer and whiskey with @crisberrios one day
Cristián Berríos
@crisberrios
Mar 05 2015 04:45 UTC
return _.flatten(arr);
:shipit:
Nathan
@terakilobyte
Mar 05 2015 04:46 UTC
Ramda also has a flatten
Cristián Berríos
@crisberrios
Mar 05 2015 04:46 UTC
but it's aliased to _ right?
Nathan
@terakilobyte
Mar 05 2015 04:46 UTC
shouldn’t be anymore
Cristián Berríos
@crisberrios
Mar 05 2015 04:46 UTC
oh
Nathan
@terakilobyte
Mar 05 2015 04:47 UTC
I was getting some confusion about _ not being lodash
Cristián Berríos
@crisberrios
Mar 05 2015 04:47 UTC
so return R.flatten(arr):
did you know there's a fp_lodash now?
or fp-lodash
Nathan
@terakilobyte
Mar 05 2015 04:47 UTC
I’m really trying to make the bonfires instructional and not pull your hair out why isn’t this working
I didn’t, I’ll have to check it out
Cristián Berríos
@crisberrios
Mar 05 2015 04:48 UTC
same functions but data last
Nathan
@terakilobyte
Mar 05 2015 04:48 UTC
the level 4 and 5 bonfires will be pull your hair out why isn’t this working though
awesome
data last is the way to go
Tyler Haas
@tylerthehaas
Mar 05 2015 04:48 UTC
is that a javascript function or out of a library?
Cristián Berríos
@crisberrios
Mar 05 2015 04:48 UTC
@dannyfritz was commenting that the developer of lodash approached him to use it instead of ramda xD
@haasDev library
Nathan
@terakilobyte
Mar 05 2015 04:48 UTC
lol, yeah I heard him say that
the ramda guys are great though and super helpful
so I’ll probably stick with it, that and it works
Cristián Berríos
@crisberrios
Mar 05 2015 04:49 UTC
I'm going to learn RX jhusain.github.io/learnrx/
Nathan
@terakilobyte
Mar 05 2015 04:49 UTC
no sense abandoning a library I’m learning to learn another one
good idea!
we’re going to be using it on fcc
Cristián Berríos
@crisberrios
Mar 05 2015 04:50 UTC
seems a good idea for the portfolio
to do a demo with rx
Nathan
@terakilobyte
Mar 05 2015 04:50 UTC
fcc will be a react/flux/rxjs app soon enough
Cristián Berríos
@crisberrios
Mar 05 2015 04:50 UTC
that's nice. Is there a more popular library than rx that does about the same?
Nathan
@terakilobyte
Mar 05 2015 04:51 UTC
so aside from crockford being kind of a douche about the syntax highlighting in that video I linked earlier, it does have good info @crisberrios
give it a watch if you haven't
Nathan
@terakilobyte
Mar 05 2015 04:51 UTC
I think bacon.js?
not sure if it’s more popular though
but it does have a great name
Julie Myers
@BlueOceanView
Mar 05 2015 04:51 UTC
Oh, I thought bacon.js was a joke.
I mean I thought you were making a funny when you said bacon.js
Nathan
@terakilobyte
Mar 05 2015 04:52 UTC
lol
it actually is real
which is more awesome than a joke would have been :)
Julie Myers
@BlueOceanView
Mar 05 2015 04:52 UTC
People are making all sorts of products to smell and/or taste like bacon.
Nathan
@terakilobyte
Mar 05 2015 04:53 UTC
well, it’s nature’s perfect fruit
and one of the 4 food groups
salt, sugar, fat, bacon
Julie Myers
@BlueOceanView
Mar 05 2015 04:53 UTC
My neighbors would agree with you, that it's natures perfect fruit.
Cristián Berríos
@crisberrios
Mar 05 2015 04:53 UTC
lol
a perfect dessert for a platter of turf & turf
Julie Myers
@BlueOceanView
Mar 05 2015 04:55 UTC
@haasDev This should help:
var myArray =[[[1,2],[3,4]],[[5,6],[7,8]],[[9,0]]];
var myFlatArray = myArray.toString().split(',').map(function(e) { return parseInt(e); });
myFlatArray;
Results - [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
Tyler Haas
@tylerthehaas
Mar 05 2015 04:56 UTC
thats originally what i did but it breaks down when it comes to the test for letters
Cristián Berríos
@crisberrios
Mar 05 2015 04:57 UTC
of course, that only works if your array does not have entries like ["1,2","3,4"]
you can use return parseInt(e) || e
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 04:58 UTC
Hey I've got a question on Atom
How do I install packages?
where do I enter this code?
like I have the code $ apm install linter
Julie Myers
@BlueOceanView
Mar 05 2015 05:00 UTC
function steamroller(arr) {
  var myFlatArray = arr.toString().split(',').map(function(e){ 
    return parseInt(e) || e; 
  });
  return myFlatArray;
}

steamroller([1, [2], [3, [[4]]]]);
Pass the first two tests. But, fails the test that has an empty array.
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 05:03 UTC
Okay got it!
Nathan
@terakilobyte
Mar 05 2015 05:03 UTC
you could always just call join(‘,’)
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 05:03 UTC
I'm suppose to do it on the terminal
Nathan
@terakilobyte
Mar 05 2015 05:03 UTC
it will flatten your array into a string
thensplit it on commas to get your flat array
Tyler Haas
@tylerthehaas
Mar 05 2015 05:04 UTC
I originally did that but it didn't seem to handle the arrays that are 3 or 4 levels deep but maybe I just didn't take the idea far enough
Nathan
@terakilobyte
Mar 05 2015 05:05 UTC
consider
[[[1, 2], [3, 44]], 5].join(',')
.split(',')
.map(function(elem) {
  return parseInt(elem, 10);
})
returns [1, 2, 3, 44, 5]
Julie Myers
@BlueOceanView
Mar 05 2015 05:08 UTC
function steamroller(arr){
  arr.join(',').split(',').map(function(elem) {
  return parseInt(elem, 10);
  });
}

steamroller([1, [2], [3, [[4]]]]);
All tests failed.
Cristián Berríos
@crisberrios
Mar 05 2015 05:09 UTC
you have to assign the value
and return it
or just return it
Nathan
@terakilobyte
Mar 05 2015 05:10 UTC
^
I just copied/pasted what I had typed in the console to proof it
not goign to give you the entire bonfire answer
Darryl Dixon - Piece Digital
@piecedigital
Mar 05 2015 05:11 UTC
aren't there letters and empty strings in there as well?
Nathan
@terakilobyte
Mar 05 2015 05:11 UTC
again, not going to give the entire bonfire answer
Cristián Berríos
@crisberrios
Mar 05 2015 05:20 UTC
I've found some good beginner resources on Rx
I think it's the reactive library to go
the other alternatives don't seem as mature or community-supported
Julie Myers
@BlueOceanView
Mar 05 2015 05:21 UTC
function steamroller(arr){
  var a = arr.join(',').split(',').map(function(elem) {
    return parseInt(elem, 10) || elem || '';
  });
  return a;
}

steamroller([1, [2], [3, [[4]]]]);
Fails the test where there is an empty array. Any hints on how to deal with an empty array?
Cristián Berríos
@crisberrios
Mar 05 2015 05:22 UTC
filter?
.filter(function(i) { return i } );
I use that to filter empty items on mapped arrays
Nathan
@terakilobyte
Mar 05 2015 05:24 UTC
^
Julie Myers
@BlueOceanView
Mar 05 2015 05:25 UTC
My brain hurts. It's not that important for me to finish it. I just do the bonfires to get good at figuring out how solve a problem step by step.
Nathan
@terakilobyte
Mar 05 2015 05:26 UTC
chain filter to the end
return arr. join
.split
.map
.filter
Cristián Berríos
@crisberrios
Mar 05 2015 05:32 UTC
speaking of arrays
read the first paragraph :P
Nathan
@terakilobyte
Mar 05 2015 05:33 UTC
@crisberrios add this to your reading list
Cristián Berríos
@crisberrios
Mar 05 2015 05:33 UTC
Actually, I'm reading that
just started
Nathan
@terakilobyte
Mar 05 2015 05:35 UTC
ok cool
just wanted to share resources
and yeah, that first paragraph
I think I’ve said it on stream like a thousand times
learn map, filter, and reduce
Cristián Berríos
@crisberrios
Mar 05 2015 05:37 UTC
Nathan
@terakilobyte
Mar 05 2015 05:38 UTC
cool, added to my reading list
Julie Myers
@BlueOceanView
Mar 05 2015 05:41 UTC
function steamroller(arr){
  var a = arr.join(',').split(',').map(function(elem) {
    return parseInt(elem, 10);
  }).filter(function(n){ 
       return n !== null;
     });
  return a;
}

steamroller([1, [2], [3, [[4]]]]);
Closer?
!== null is not working.
Nathan
@terakilobyte
Mar 05 2015 05:45 UTC
don’t check against null
try return Boolean(n) in your filter
or, more simply, return n and filter will actually make it a boolean for you
you are checking for falseness, not nullness
the two are not equal, although null will evaluate to false
Cristián Berríos
@crisberrios
Mar 05 2015 05:48 UTC
because you would have to check if n!== null || n!==undefined || n!== '' || n!== 0 <--- oops
Julie Myers
@BlueOceanView
Mar 05 2015 05:48 UTC
Not getting it.
Nathan
@terakilobyte
Mar 05 2015 05:48 UTC
excellent catch @crisberrios
Cristián Berríos
@crisberrios
Mar 05 2015 05:49 UTC
filter checks for truthyness of the returned value
and an empty string is "falsy"
for the test cases, is enough
but if one of the items is equal to 0
it would also return false
since 0 is also falsy
Julie Myers
@BlueOceanView
Mar 05 2015 05:50 UTC
So, I get what falsies are. How do I make filter not return an empty array?
Cristián Berríos
@crisberrios
Mar 05 2015 05:50 UTC
return n
within the filter
Nathan
@terakilobyte
Mar 05 2015 05:51 UTC
so return typeof n !== ‘number’ && Boolean(n) perhaps
Cristián Berríos
@crisberrios
Mar 05 2015 05:51 UTC
function steamroller(arr) {
  var myFlatArray = arr.toString().split(',').map(function(e){ 
    return parseInt(e) || e; 
  });
  return myFlatArray;
}

steamroller([1, [2], [3, [[4]]]]);
this one + the filter worked for me
you almost had it
Julie Myers
@BlueOceanView
Mar 05 2015 05:56 UTC
function steamroller(arr) { 
  var myFlatArray = arr.toString().split(',').map(function(e){ 
    return parseInt(e) || e; 
  }).filter(function(n){
      return n;
  }); 
  return myFlatArray; 
} 

steamroller([1, [2], [3, [[4]]]]);
This worked. I will need to really study it to completely understand it. But, it's not that important. I think the idea of the exercise was to see that you can chain many methods together.
I'm pretty sure having to solve something like steamroller is not something you will see in the "real world"
Alright, that was enough useless problem solving for me. Later.
Cristián Berríos
@crisberrios
Mar 05 2015 06:07 UTC
if working in node
you will see this same problem
everyday
Julie Myers
@BlueOceanView
Mar 05 2015 06:08 UTC
really? Why does node have that problem a lot?
Cristián Berríos
@crisberrios
Mar 05 2015 06:08 UTC
call a database, receive an array of objects
do multiple queries, receive multiple arrays
now, flatten that array so you have only 1 array with objects
well... maybe flattening it yourself won't be needed
and it's certainly easier to do it with Ramda, lodash or similar functional libraries
but the problem is there
If you watch the video I posted earlier
half of the video is pretty much flattening arrays
Julie Myers
@BlueOceanView
Mar 05 2015 06:10 UTC
Would you ever receive an array in node that is 3-4 levels deep like the streamroller problem?
Cristián Berríos
@crisberrios
Mar 05 2015 06:10 UTC
sure you will
maybe not on a beginner project
but it's a common problem
Julie Myers
@BlueOceanView
Mar 05 2015 06:11 UTC
Could you give a more detailed example?
Cristián Berríos
@crisberrios
Mar 05 2015 06:14 UTC
hmmm let me thing
think
for example, a function to calculate how money does a person have
that person has boxes
inside the boxes has money floating around
but it can also have purses with money
and a bank account with a savings account and a checking account
if you aggregate the data, you get multiple nested arrays with values you want to sum
Julie Myers
@BlueOceanView
Mar 05 2015 06:16 UTC
Basically, node does the flattening for me. But, it's interesting to know how the coding works.
Cristián Berríos
@crisberrios
Mar 05 2015 06:16 UTC
not node
but a function or a library
Harshal
@McQuinTrix
Mar 05 2015 06:17 UTC

@crisberrios I am getting the result in JavaScript console .. but here it is not being accepted :

function destroyer(arr) {
// Remove all the values
for(var i=1;i<arguments.length;++i){
var b = arguments[i];
arr = arr.filter(function(element){console.log(b+' '+ i);return element!=b;});
}
return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

this is seek and destroy bonfire challenge (:

Julie Myers
@BlueOceanView
Mar 05 2015 06:17 UTC
Oh...you said if working in node I'll see this same problem everyday.
Cristián Berríos
@crisberrios
Mar 05 2015 06:18 UTC
more simple
you call an api
and it returns arrays of values in chunks
so you have [1,2],[3,4,5],[6]
in a pub/sub model
like an online chat
you will be pushing messages to a queue
then reading them from somewhere else
as you read
you will have an array with different number of messages
which are arrays
that would be a simple case of use
Julie Myers
@BlueOceanView
Mar 05 2015 06:21 UTC
I get the idea of flattening an array. But, what I'm not to sure about is having to deal with an array that is several levels deep like: [1, [2], [3, [[4]]]]
Cristián Berríos
@crisberrios
Mar 05 2015 06:21 UTC
@McQuinTrix you overwrite the array each time the for loop runs
Julie Myers
@BlueOceanView
Mar 05 2015 06:22 UTC
I just have a hard time believing I'ld see that complex of an array on average in the real world.
Cristián Berríos
@crisberrios
Mar 05 2015 06:22 UTC
another case of use
maybe not a best practice, but think of a library
Harshal
@McQuinTrix
Mar 05 2015 06:22 UTC
@crisberrios but the answer is coming out .. i saw in JavaScript Console :c
Cristián Berríos
@crisberrios
Mar 05 2015 06:23 UTC
a recursive function that returns [func(arr),value]
when the function returns from the nesting
that structure will be deep and weirdly nested
I don't see either having to deal with 10 levels of flattening
but 1 level is very common
2 levels is not rare
and 3 levels is still possible
@McQuinTrix check where you are logging. That doesn't mean the value is in the answer variable
Julie Myers
@BlueOceanView
Mar 05 2015 06:25 UTC
That's what I thought. I figured 1 level will be pretty common, and maybe even 2 levels. My guess is rarely 3, and almost never any deeper.
Cristián Berríos
@crisberrios
Mar 05 2015 06:27 UTC
well, if you have to deal with flattening, check lodash or ramdajs
Julie Myers
@BlueOceanView
Mar 05 2015 06:28 UTC
I'll keep that in mind. Thanks for the help @crisberrios. Honestly, if we don't have to worry about 4 level deep arrays, I say take out that exercise. Stay concentrated on what we really need to know to get a job. Just my opinion.
Cristián Berríos
@crisberrios
Mar 05 2015 06:32 UTC
well... bootcamps have to mantain a balance between proper learning and fast learning. I'm leaning towards proper learning so I value the bonfires. Of course, they can be revised and the difficulty adjusted.
since I'm an RPG games fan, I envision having multiple masters paths after the basic curriculum
one for frontend, one for backend and one for design
Julie Myers
@BlueOceanView
Mar 05 2015 06:33 UTC
Yeah, I agree about the proper learning. Fast learning in programming usually doesn't work that well. But, a bootcamp is here to prepare us for a first job. I am thinking knowing how to solve 4 level deep arrays is usually not an interview question.
The master paths sound pretty cool.
Oliver
@Dadsaster
Mar 05 2015 06:36 UTC
Can I get a second pair of eyes on this? When I test the various conditions I return the proper answer but I'm still failing to pass. Sorry it's so massive:
var draw = {};
var nameList = [];
var outArr = [];
var total = 0;

var toDraw = function(cid){
    cid.map(function(elem){
        draw[elem[0]] = [elem[1]];
        total += elem[1];
    });
};

function makeChange(diff){
    for (var key in draw) {
        var div = (diff/draw[key][2]);
        var rem = diff % draw[key][2];
        if (diff % draw[key][2] !== diff && draw[key][1] >= div && diff > 0) {
            draw[key][0] -= div*draw[key][2];
            draw[key][1] -= div;
            diff -= div*draw[key][2];
            outArr.push([key, div*draw[key][2]]);
        }
    }
}

function drawer(price, cash, cid) {
    var diff = cash - price;
    cid.reverse();
    toDraw(cid);
    if(diff > total) {
        return "Insufficient Funds";
    } else if (diff === total) {
        return "Closed";
    } else {
        for(var key in draw){
            var count = 0;
            var base = 0;
            if (key == "PENNY"){
                count = draw[key] / 0.01;
                base = 0.01;
                draw[key].push(count, base);
            } else if (key === "NICKEL"){
                count = draw[key] / 0.05;
                base = 0.05;
                draw[key].push(count, base);
            } else if (key === "DIME"){
                count = draw[key] / 0.1;
                base = 0.1;
                draw[key].push(count, base);
            } else if (key === "QUARTER"){
                count = draw[key] / 0.25;
                base = 0.25;
                draw[key].push(count, base);
            } else if (key === "ONE"){
                count = draw[key] / 1;
                base = 1;
                draw[key].push(count, base);
            } else if (key === "FIVE"){
                count = draw[key] / 5;
                base = 5;
                draw[key].push(count, base);
            } else if (key === "TEN") {
                count = draw[key] / 10;
                base = 10;
                draw[key].push(count, base);
            } else if (key === "TWENTY"){
                count = draw[key] / 20;
                base = 20;
                draw[key].push(count, base);
            } else {
                count = draw[key] / 100;
                base = 100;
                draw[key].push(count, base);
            }
        }
    }
    makeChange(diff);
    return outArr;
}

 drawer(19.50, 20.00, [['PENNY', 0.50], ['NICKEL', 0], ['DIME', 0], ['QUARTER', 0], ['ONE', 0], ['FIVE', 0], ['TEN', 0], ['TWENTY', 0], ['ONE HUNDRED', 0]]);
Cristián Berríos
@crisberrios
Mar 05 2015 06:39 UTC
well... you might want to turn that unholy tower of if-else into a switch statement :P
and I'm not sure, but when dealing with money, you want to use .toPrecision
since 0.1 + 0.2 !== 0.3
Julie Myers
@BlueOceanView
Mar 05 2015 06:40 UTC
Ewwww...I heard using switch is way out of date.
Just sayin...
Cristián Berríos
@crisberrios
Mar 05 2015 06:40 UTC
@BlueOceanView there are better ways, yes
but for the purpose of learning
it's way better than having if-else-if-else
Julie Myers
@BlueOceanView
Mar 05 2015 06:40 UTC
true that.
It would be cool if FCC figured out how to teach best practices though. I think people may be teaching themselves some bad coding practices.
well enough complaining. I'm turning off my computer.
Darryl Dixon - Piece Digital
@piecedigital
Mar 05 2015 06:42 UTC
I got close to solving this
Cristián Berríos
@crisberrios
Mar 05 2015 06:42 UTC
function > object > switch > if-else
Oliver
@Dadsaster
Mar 05 2015 06:43 UTC
I appreciate the looks but my problem is when I'm returning "Insufficient funds" or "Closed" I'm doing it on the right test cases but I still am not passing those cases.
Cristián Berríos
@crisberrios
Mar 05 2015 06:43 UTC
how close @piecedigital
let me check your code against the bonfire
Oliver
@Dadsaster
Mar 05 2015 06:44 UTC
And I hate the if/else tower - it makes me feel all icky in side. My plan was to solve it first then improve.
@crisberrios I appreciate it!
I'm probably missing something obvious
Cristián Berríos
@crisberrios
Mar 05 2015 06:47 UTC
well, I see that you are returning an array, and it's expecting a string?
Oliver
@Dadsaster
Mar 05 2015 06:48 UTC
I see that too but it isn't the case - I'm returning an array only when something in the register has changed or else I'm returning a string. Am I getting the output wrong?
Cristián Berríos
@crisberrios
Mar 05 2015 06:50 UTC
I haven't solved this one
I'll give it a try tomorrow, since I'm a bit tired now
Oliver
@Dadsaster
Mar 05 2015 06:51 UTC
No worries - I'll look at it again with fresh eyes - thanks again
Cristián Berríos
@crisberrios
Mar 05 2015 06:52 UTC
yw, hope you solve it!
Harshal
@McQuinTrix
Mar 05 2015 07:40 UTC
i still dont know why this doesnt work :
function destroyer(arr) {
// Remove all the values
for(var i=1;i<arguments.length;++i){
var b = arguments[i];
arr = arr.filter(function(element){console.log(b+' '+ i);return element!=b;});
}
return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
not this .. sorry: this :
function destroyer(arr) {
// Remove all the values
for(var i=1;i<arguments.length;++i){
var b = arguments[i];
arr = arr.filter(function(element){return element!=b;});
}
return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Darryl Dixon - Piece Digital
@piecedigital
Mar 05 2015 08:44 UTC
it worked.
@McQuinTrix
IDK why. Try copying your code and refreshing the browser.
Harshal
@McQuinTrix
Mar 05 2015 08:47 UTC
dudeeeeeeee .. awesomeeee .. thank you .. hahahah ... i was checking it with console.log still in there
i am so dumb man
Darryl Dixon - Piece Digital
@piecedigital
Mar 05 2015 08:47 UTC
Lol, don't worry about it :+1:
Harshal
@McQuinTrix
Mar 05 2015 08:47 UTC
@piecedigital do you know any better method to do this
or this is optimal ?
Darryl Dixon - Piece Digital
@piecedigital
Mar 05 2015 08:48 UTC
I think this is about as good as it gets IMO. My solution was longer, but I spelled out the steps a bit more.
Harshal
@McQuinTrix
Mar 05 2015 08:49 UTC
I was trying to find another solution lesser than this for 1-2 hours .. maybe there is a smaller using filter and forEach together .. but i have lost energy right now .. tiredd
@piecedigital anyway thanks man (:
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 08:53 UTC
$(document).ready(function(){
  $('h1').on('click', function(){
    $('h1').addClass('animated flash');
  });
});
This code is fine right?
Harshal
@McQuinTrix
Mar 05 2015 08:56 UTC
looks fine yeah ..
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 08:56 UTC
I found my problem!!!
Harshal
@McQuinTrix
Mar 05 2015 08:56 UTC
good (:
Ammar Ali Shah
@AmmarAliShah
Mar 05 2015 08:57 UTC
and it was the most stupidest one I can imagine
It just hit me: I didn't add the jQuery library
Harshal
@McQuinTrix
Mar 05 2015 08:59 UTC
xD
Darryl Dixon - Piece Digital
@piecedigital
Mar 05 2015 11:18 UTC
@AmmarAliShah classes and ID's don't have spaces, unless it's two different classes.
Nathan
@terakilobyte
Mar 05 2015 11:19 UTC
if he’s using animate.css he’s doing it right, dunno if there is a flash class though
Evan Davis
@davisec52
Mar 05 2015 15:32 UTC

Good morning! Trying to solve Bonfires challenge "Convert
HTML Entities" by using a switch statement.

The code sample below does not work, and I'd appreciate
help understanding how to fix it.


function convert(str) {

        switch(str) {
        case "str.match(/</g)":
            str = str.replace(/</g, "&lt;");
            break;

        case "str.match(/>/g)":
            str = str.replace(/\>/g, "&gt;");
            break;

        case "str.match(/\"/g)":
            str = str.replace(/\"/g, "&quot;");
            break;

        case "str.match(/\'/g)":
            str = str.replace(/\'/g, "&apos;");
            break;

        case "str.match(/&/g)":
            str = str.replace(/\&/g, "&amp;");
            break;

        case "str.match(/,/g)":
            str = str.replace(/,/g, "&comma;");
            break;

        default:
            return "Enter a valid string."; 
    }

 return str;
}
convert('Dolce & Gabbana');
The result should be: 'Dolce & Gabbana'
Nope
should be the entity code in place of &.
Julie Myers
@BlueOceanView
Mar 05 2015 16:13 UTC
@davisec52 Run for the hills! :P Don't use the switch statement. It's no longer used out in the real world. Though if you want to just to solve the bonfire...
Evan Davis
@davisec52
Mar 05 2015 16:15 UTC
@BlueOceanView Hi there!
I've heard that it is on the way out
I solved the bonfire using a different solution but wanted to try it this way.
Andrew Corcoran
@corca
Mar 05 2015 16:34 UTC
@davisec52 I was curious why that wouldn’t work and it turns out that the match() method returns an array.
So you’re comparing your initial str to the entire returned array
Evan Davis
@davisec52
Mar 05 2015 16:36 UTC
@corca Hmm
Thank you
Andrew Corcoran
@corca
Mar 05 2015 16:37 UTC
Also I don’t think you can run str.match() inside quotes
Evan Davis
@davisec52
Mar 05 2015 16:37 UTC
So I need to tinker with this
Andrew Corcoran
@corca
Mar 05 2015 16:37 UTC
Yeah I’m playing with it to see if I can’t make it work
Danny Fritz
@dannyfritz
Mar 05 2015 16:37 UTC
I think there are more problems with it:
  1. case expressions can only be values. it matches the switch input with a === to test each case.
  2. this will only run str through once, effectively only catching one of the characters in the string instead of all of them.
  3. default returns when the other cases do not
Evan Davis
@davisec52
Mar 05 2015 16:37 UTC
I tried it without quotes but was not productive

str = 'XYZ test';
switch (str) {
  case (str.match(/^xyz/) || {}).input:
    console.log("Matched a string that starts with 'xyz'");
    break;
  case (str.match(/test/) || {}).input:
    console.log("Matched the 'test' substring");        
    break;
  default:
    console.log("Didn't match");
    break;
}
code sample from stackoverflow
Andrew Corcoran
@corca
Mar 05 2015 16:39 UTC
I think replacing the switch expression with a boolean value and then running a str.search would work better?
Evan Davis
@davisec52
Mar 05 2015 16:39 UTC
@corca Yes, I think that would make more sense.
@dannyfritz I can see I definitely need to work on this.
Miguel Sanchez
@miguedep
Mar 05 2015 16:41 UTC
hi, anyone can help me with prestashop? I'd like to update a field in mysql with Db::getInstance()
Danny Fritz
@dannyfritz
Mar 05 2015 16:42 UTC
@miguedep you should probably be using prestashop's communities for help with prestashop https://www.prestashop.com/en/community
Miguel Sanchez
@miguedep
Mar 05 2015 16:44 UTC
@dannyfritz thanks, I tried to but I couldn't solve the problem. Anyway, you're right better ask in a more appropiate place.
Andrew Corcoran
@corca
Mar 05 2015 17:08 UTC
@davisec52
function convert(str) {
        switch(true) {
        case (str.search(/</g) >= 0):
            str = str.replace(/</g, "&lt;");
            break;

        case (str.search(/>/g) >= 0):
            str = str.replace(/\>/g, "&gt;");
            break;

        case (str.search(/\"/g) >= 0):
            str = str.replace(/\"/g, "&quot;");
            break;

        case (str.search(/\'/g) >= 0):
            str = str.replace(/\'/g, "&apos;");
            break;

        case (str.search(/&/g) >= 0):
            str = str.replace(/\&/g, "&amp;");
            break;

        case (str.search(/,/g) >= 0):
            str = str.replace(/,/g, "&comma;");
            break;

        default:
            return "Enter a valid string."; 
    }

 return str;
}
alert(convert('Dolce & Gabbana'));
The problem with this code is that it will only evaluate one case statement. You would need to remove the breaks to evaluate all of them in order.
So
function convert(str) {
        switch(true) {
        case (str.search(/</g) >= 0):
            str = str.replace(/</g, "&lt;");
        case (str.search(/>/g) >= 0):
            str = str.replace(/\>/g, "&gt;");
        case (str.search(/\"/g) >= 0):
            str = str.replace(/\"/g, "&quot;");
        case (str.search(/\'/g) >= 0):
            str = str.replace(/\'/g, "&apos;");
        case (str.search(/&/g) >= 0):
            str = str.replace(/\&/g, "&amp;");
        case (str.search(/,/g) >= 0):
            str = str.replace(/,/g, "&comma;”);
            break;
        default:
            return "Enter a valid string."; 
    }
 return str;
}
convert('Dolce & Gabbana’);
Danny Fritz
@dannyfritz
Mar 05 2015 17:10 UTC
are these even valid JS?
Andrew Corcoran
@corca
Mar 05 2015 17:13 UTC
Iffy, without the break at each case statement, it’s not good.
Even then, there are better ways to do it.
@davisec52 was just curious if it was possible this way.
Evan Davis
@davisec52
Mar 05 2015 17:15 UTC
@corca Thank you. In my thick headedness, I probably would not have thought to remove the break statements.
Does not appear to run in repl.it
Andrew Corcoran
@corca
Mar 05 2015 17:17 UTC
Check that last single quote in the the convert call for ‘Dolce & Gabbana'
Or every quote for that matter...
Evan Davis
@davisec52
Mar 05 2015 17:25 UTC
Interesting. This is actually much more difficult
than solutions using if-statements or just a
series of .replace calls.

function convert(str) {
        switch(true) {
        case (str.search(/</g) >= 0):
            str = str.replace(/</g, "&lt;");
            break;
        }
}
convert("Dolce < Gabbana");  //blank return
Andrew Corcoran
@corca
Mar 05 2015 17:27 UTC
Yep.
Jon Lucas
@jonslucas
Mar 05 2015 18:12 UTC
Has anyone completed no-repeats using a mostly math approach? I think I've got it for a single case of double chars, but the double doubles are killing me
Avremel Kaminetzky
@avremel
Mar 05 2015 18:34 UTC
This message was deleted
Seek and Destroy Bonfire: I have no clue how the second argument is being passed into function.
function destroyer(arr) {
  // Remove all the values
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
These are the instructions:
Remove all values (last argument(s)) from an array (first argument) and return as a new array.
Stefan
@worzst
Mar 05 2015 18:39 UTC
I just took the last 2 in the array and it worked.. I was confused too and couldn’t tell them apart
Avremel Kaminetzky
@avremel
Mar 05 2015 18:40 UTC
Ok thanks @worzst I will try that out
Danny Fritz
@dannyfritz
Mar 05 2015 18:40 UTC
@jonslucas i'm working on one, i think i might be onto something.
Germaine Pannell
@germainep
Mar 05 2015 18:49 UTC
working on Cash Register and we are failing one case and we can't figure out why
here's our code
function drawer(price, cash, cid) {
    var change = cash - price;
    var baseVal = [100, 20, 10, 5, 1, 0.25, 0.10, 0.05, 0.01];
    var reverseCID = cid.reverse();
    var out = [];
    var total = 0;
    var bigNum = 0;
    var remain = 0;
    //total drawer
    reverseCID.map(function(elem){
        total += elem[1];
    });
    console.log(total);
    // create if / if else for string cases
    if(total === change){
        return "Closed";
    } else if(total < change){
        return "Insufficient Funds";
    }else {
        for (var i = 0; i < reverseCID.length; i++) {

            bigNum = (parseInt(change/baseVal[i], 10));
            console.log(bigNum);
            if (bigNum >= 1 && change > 0) {
              var billVal= bigNum*baseVal[i];
                out.push([reverseCID[i][0], billVal]);
                change -= bigNum*baseVal[i];
            }
        }
    }
    // if change is made 
        // iterate through reverseCID array
            //push change to output array

    return out;
}

// Example cash-in-drawer array:
// [['PENNY', 1.01],
// ['NICKEL', 2.05],
// ['DIME', 3.10],
// ['QUARTER', 4.25],
// ['ONE', 90.00],
// ['FIVE', 55.00],
// ['TEN', 20.00],
// ['TWENTY', 60.00],
// ['ONE HUNDRED', 100.00]]

drawer(3.26, 100.00, [['PENNY', 1.01], ['NICKEL', 2.05], ['DIME', 3.10], ['QUARTER', 4.25], ['ONE', 90.00], ['FIVE', 55.00], ['TEN', 20.00], ['TWENTY', 60.00], ['ONE HUNDRED', 100.00]]);
Evan Davis
@davisec52
Mar 05 2015 18:58 UTC
Jon Lucas
@jonslucas
Mar 05 2015 18:59 UTC
@worzst you should also check out this ^ link. arguments is super useful!
@germainep Which one are you failing on?
@dannyfritz I'm gonna keep trying to figure it out, but the 'abfdefa' case is my final hurdle
Danny Fritz
@dannyfritz
Mar 05 2015 19:01 UTC
@jonslucas what is the logic behind yours
Jon Lucas
@jonslucas
Mar 05 2015 19:01 UTC
Basically, I'm looking for a solution where I don't have to parse out all of the permutations
Danny Fritz
@dannyfritz
Mar 05 2015 19:01 UTC
i'm toying around with the idea of treating double repeats of a sequence as a single symbol and subtracting out those combinations
Jon Lucas
@jonslucas
Mar 05 2015 19:02 UTC
basically, for a single double I was able to use something like this:
Danny Fritz
@dannyfritz
Mar 05 2015 19:02 UTC
factorial(n) - factorial(n-1)
Jon Lucas
@jonslucas
Mar 05 2015 19:03 UTC
I've got n! - ((n-1)(2(x-2)!))
Danny Fritz
@dannyfritz
Mar 05 2015 19:03 UTC
what is the x
Jon Lucas
@jonslucas
Mar 05 2015 19:04 UTC
sorry lol
that x should be an n
Danny Fritz
@dannyfritz
Mar 05 2015 19:04 UTC
is 2 the length of the repeat? like 2 a's in the sequence?
Germaine Pannell
@germainep
Mar 05 2015 19:04 UTC
@jonslucas I figured out why its failing thanks
Jon Lucas
@jonslucas
Mar 05 2015 19:05 UTC
@germainep you're welcome
@dannyfritz this is gonna be a little long winded, but I'll try to keep it short
So, in the output for 'aab' as the input string, it breaks into 3 sets of 2!: ['aab', 'aba'] for example, where the initial 'a' is the same 'a', if that makes sense
Danny Fritz
@dannyfritz
Mar 05 2015 19:08 UTC
okay cool i think i got it
what are some test cases i can use
Jon Lucas
@jonslucas
Mar 05 2015 19:08 UTC
I've used 'aab', 'aabc', and 'aabb'
Danny Fritz
@dannyfritz
Mar 05 2015 19:09 UTC
what are the expected outputs
'aabb' returns 0 :(
Jon Lucas
@jonslucas
Mar 05 2015 19:09 UTC
but the 'aabb' test is tenuous. I don't think it should work, but it does
yeah, sorry, I'm going off of hand written notes and it's all over the place
Danny Fritz
@dannyfritz
Mar 05 2015 19:10 UTC
this is what i got going for me: http://jsbin.com/lunoditila/1/edit?js,console
Jon Lucas
@jonslucas
Mar 05 2015 19:10 UTC
for the double doubles like 'aabb', the formula becomes: n! - ((n)(2(n-2)!)
so the n-1 from the first case becomes just n
Danny Fritz
@dannyfritz
Mar 05 2015 19:10 UTC
because you treat it like 'ab'
and each permutation thereof is invalid
Jon Lucas
@jonslucas
Mar 05 2015 19:11 UTC
Could you say a little more about what you mean? I don't think I understand
Not enough coffee
Danny Fritz
@dannyfritz
Mar 05 2015 19:12 UTC
'aab' can be expanded to 'aab', 'aab', 'aba', 'aba', 'baa', 'baa'
2 of those are valid
4 are not
Jon Lucas
@jonslucas
Mar 05 2015 19:13 UTC
Right, gotcha
Danny Fritz
@dannyfritz
Mar 05 2015 19:13 UTC
they way i see the invalid ones are any permutation where 'aa' exists
so if you reduce 'aa' to 'a' you get 'ab'
each permutaiton of the new invalid 'aa' is 'ab', 'ba'
you multiply by 2 to get how many there would be because 'aa' has 2 permutations itself
and subtract it out
6-4 = 2
Jon Lucas
@jonslucas
Mar 05 2015 19:14 UTC
I like that a lot more than how I was looking at it
So then how would you expand that to the 'aabb' case?
Danny Fritz
@dannyfritz
Mar 05 2015 19:14 UTC
aa -> a'
well i see there are 2 a's and 2 b's
aa -> a' = a'bb
a'bb, ba'b, bba'
*2 = 6
then bb -> b'
aab', ab'a, b'aa
*2 = 6
24 - 6 - 6 = 12
Jon Lucas
@jonslucas
Mar 05 2015 19:16 UTC
But it should be 16 for that one, I think
Danny Fritz
@dannyfritz
Mar 05 2015 19:16 UTC
are you sure? i got 12 when i did it by hand
Jon Lucas
@jonslucas
Mar 05 2015 19:16 UTC
since the assert checks for 8
'aabc' would be 12, from my calculations
Avremel Kaminetzky
@avremel
Mar 05 2015 19:17 UTC
@davisec52 Thanks for that, I never knew
Danny Fritz
@dannyfritz
Mar 05 2015 19:17 UTC
ah yeah, you're correct
Jon Lucas
@jonslucas
Mar 05 2015 19:17 UTC
so maybe its 2^2 for 'aab'
Danny Fritz
@dannyfritz
Mar 05 2015 19:17 UTC
@jonslucas i'm double counting
a'bb is the same as aab'
Jon Lucas
@jonslucas
Mar 05 2015 19:17 UTC
which just happens to be 2*2
so that you would get something like 2^4 out from 'aabb'
then it would be 24-16
Danny Fritz
@dannyfritz
Mar 05 2015 19:18 UTC
what if i did aa => a', bb => b'
a'b', b'a'
*4
=8
24-8
Jon Lucas
@jonslucas
Mar 05 2015 19:19 UTC
8 should be the return value, i.e. those left over once the sequential dups are removed
Danny Fritz
@dannyfritz
Mar 05 2015 19:19 UTC
shucks. this is tough
Jon Lucas
@jonslucas
Mar 05 2015 19:19 UTC
permAlone('aabb') -> 8
Yeah, I've spent about 12 hours thinking about how to derive this
Basically, I've been able to see that something weird happens when you move from 'aabb' to 'aabbc' such that my equation breaks down
'aabbc' should remove 14 for every 4! subset
but my calcs return 12 there
any my calc is short by 6! on the 'abfdefa' case they test for
*and
Cristián Berríos
@crisberrios
Mar 05 2015 19:25 UTC
@dannyfritz I made my algorithm work with very long srings :D
strings
a....za now takes less than 1 sec
Danny Fritz
@dannyfritz
Mar 05 2015 19:25 UTC
@crisberrios yours is non-recurisive right?
Cristián Berríos
@crisberrios
Mar 05 2015 19:25 UTC
:shipit:
it is recursive
Danny Fritz
@dannyfritz
Mar 05 2015 19:26 UTC
you must share it again. :P
Jon Lucas
@jonslucas
Mar 05 2015 19:26 UTC
Noo
don't do it
Danny Fritz
@dannyfritz
Mar 05 2015 19:26 UTC
you must pm me
Cristián Berríos
@crisberrios
Mar 05 2015 19:29 UTC
I'm going to get some lunch. I'll send it to you when I get back
Danny Fritz
@dannyfritz
Mar 05 2015 19:29 UTC
k
maybe i'll crack the code by then!
Suzanne Atkinson
@AdventureBear
Mar 05 2015 19:58 UTC
@terakilobyte :point_up: March 4 2015 10:56 PM Yes and yes
Suzanne Atkinson
@AdventureBear
Mar 05 2015 20:29 UTC
Just watched that philip roberts video...well mostly done. watching his interactive tool run (Loupe), the event loop to me is a way of managing tasks & interruptions. It's like working in the ER. There is only one of me, but there are many things going on at once because I task others to take care of small bits. When a piece of information is ready (reviewing lab tests), the nurse will wait till I am "interruptable" (ie my call stack is empty) then let me know tests are back (or patient is in pain or whatever). Cool stuff
Cristián Berríos
@crisberrios
Mar 05 2015 20:32 UTC
what video=
?
btw, I'm back
Hey Suzanne
event loop makes total sense now
"don't block the event loop". I'm in the know now. :)
Cristián Berríos
@crisberrios
Mar 05 2015 20:35 UTC
that's the key to understand applications in Node
Suzanne Atkinson
@AdventureBear
Mar 05 2015 20:36 UTC
even non node js, right?
Nathan
@terakilobyte
Mar 05 2015 20:40 UTC
yes even non node
the event loop is all js
Suzanne Atkinson
@AdventureBear
Mar 05 2015 20:47 UTC
that visualization was key for me
i'm going to write an essay "Understanding the JavaScript Event Loop for Emergency Physicians"
https://code.google.com/p/v8/ "V8 is Google's open source JavaScript engine. V8 is written in C++"
Hmm...
I guess the engine has to be written in another language.
Suzanne Atkinson
@AdventureBear
Mar 05 2015 20:53 UTC
so now back to my MDN Documetation and Mutants...
Cristián Berríos
@crisberrios
Mar 05 2015 20:53 UTC
not necessarily
but JS can't compile to machine language
(yet)
a C++ compiler can be written in C, or C++
now... there are C compilers written in JS
so you could theoretically build a native JS interpreter in JS
Suzanne Atkinson
@AdventureBear
Mar 05 2015 21:02 UTC
that sounds like someone would have done it already!? it's a bit beyond me at the moment, but maybe you and Nathan can do it. ;)
Cristián Berríos
@crisberrios
Mar 05 2015 21:04 UTC
writing a compiler is a big thing. If you read Eloquent JS, one chapter is writing a compiler for a simple language
anyways, it's time for my "jQuery of the day"
I don't want to break the streak
I'm having a lot of fun doing smal jquery thingies in codepen
Suzanne Atkinson
@AdventureBear
Mar 05 2015 21:09 UTC
cool, do share
EJS is on my list
Cristián Berríos
@crisberrios
Mar 05 2015 21:10 UTC
Cristián Berríos
@crisberrios
Mar 05 2015 21:16 UTC
I think I'll make a small little game
softeg
@softeg
Mar 05 2015 21:22 UTC
PLZ can anyone explain me the .beep class antenna robot i don't understand this ?
Cristián Berríos
@crisberrios
Mar 05 2015 21:33 UTC
what part you don't understand?
Danny Fritz
@dannyfritz
Mar 05 2015 21:34 UTC
cool material design forms @crisberrios
Suzanne Atkinson
@AdventureBear
Mar 05 2015 21:42 UTC
I"m thinking map is not the tool to use for mutants. because I don't want to transform anything, I want to compare the elements within them
Chris Dziewa
@chrisdziewa
Mar 05 2015 21:59 UTC
@AdventureBear there's always the new forEach method
Suzanne Atkinson
@AdventureBear
Mar 05 2015 22:01 UTC
I see an opportunity for a parallel learning track for bonfires, one in which you know the method (or one of 2 or 3) and need to implement a new creative use of it. Get to know the methods and make something happen. Then the next step could be the progressively harder bonfires.
i'm looking at every right now
every method. Not sure that works
Chris Dziewa
@chrisdziewa
Mar 05 2015 22:02 UTC
what are you working on?
jonnydc
@jonnydc
Mar 05 2015 22:08 UTC
hi
Suzanne Atkinson
@AdventureBear
Mar 05 2015 22:17 UTC
mutants
wanna pair for a few? @chrisdziewa
hi @jonnydc
Chris Dziewa
@chrisdziewa
Mar 05 2015 22:24 UTC
@AdventureBear sure
Suzanne Atkinson
@AdventureBear
Mar 05 2015 22:29 UTC
lemme find SH
Cristián Berríos
@crisberrios
Mar 05 2015 22:45 UTC
http://codepen.io/crisberrios/full/raZBzz/ some progress @AdventureBear
Briana Swift
@brianamarie
Mar 05 2015 22:52 UTC
Hey all! I'm on the "Where art thou" bonfire, and I'm feeling pretty lost as to where to start. I have tried searching through it as an array, but I don't know how to search for a specefic key within that...does anyone have any tips on what direction I should be going? Meanwhile I'm googling and reading :)
Cristián Berríos
@crisberrios
Mar 05 2015 22:56 UTC
Object.keys is your friend :D
and object bracket notation
Briana Swift
@brianamarie
Mar 05 2015 22:57 UTC
yay! thank you. :)
Cristián Berríos
@crisberrios
Mar 05 2015 22:59 UTC
yw :)
Meta Hirschl
@MetaCoderHirschl
Mar 05 2015 23:51 UTC
question/help! I'm working on bonfire 'Diff Two Arrays' and I'm getting the correct result with tests but not passing...hm.. any ideas?~~~
function diff(a1, a2) {
  var o1={}, o2={}, diffs=[], i, len, k;

  for (i=0, len=a1.length; i<len; i++) {
      o1[a1[i]] = true; 
  }
  for (i=0, len=a2.length; i<len; i++) { 
      o2[a2[i]] = true; 
  }
  for (k in o1) { 
      if (!(k in o2)) {
          diffs.push(k); 
      } 
  }
  for (k in o2) { 
      if (!(k in o1)) { 
          diffs.push(k); 
      } 
  }
  console.log(diffs);
  return diffs;
}


diff([1, 'calf', 3, 'piglet'], [1, 'calf', 3, 4]);