These are chat archives for FreeCodeCamp/Help

4th
Mar 2015
Chris Dziewa
@chrisdziewa
Mar 04 2015 00:46
@fvntr Sorry I didn't see your message. I won't able to pair anymore today. Maybe tomorrow if you are free during the day.
Phillip Ventura
@fvntr
Mar 04 2015 00:50
ok
Evan Davis
@davisec52
Mar 04 2015 15:25
Good morning. I was wondering . . . the code sample below removes
duplicates, but I don't understand how it works. I understand that
the filter method specifies setting the boolean to true or false
depending on whether you want to keep the element. In this sample, you can change the boolean to anything (for example, string or number) and the function works. Also, aside from the boolean issue, I just don't get how it removes duplicates.

function arr(array) {
var temp = {};
  for (var i = 0; i < array.length; i++)
  temp[array[i]] = true;
  console.log(temp);
  var r = [];
  for (var k in temp)
  r.push(k);
  return r;
}
arr([1, 2, 3, 5, 7, 2, 1, 4, 2, 1, 7]);  //[ '1', '2', '3', '4', '5', '7' ]
Vince
@Vince33
Mar 04 2015 15:33
Hey guys is anyone have a really strong knowledge of the ins and outs of iteration over collections of objects in arrays?
Julie Myers
@BlueOceanView
Mar 04 2015 15:33
Not really strong. But, maybe I can help you figure it out. Trying to work out @davisec52 question above.
Evan Davis
@davisec52
Mar 04 2015 15:34
@BlueOceanView Thank you! It's got me puzzled.
Vince
@Vince33
Mar 04 2015 15:34
np I am just looking for a solid resource
Evan Davis
@davisec52
Mar 04 2015 15:36
@Vince33 Hi. I do not, but @crisberrios has helped me start to get a handle on the subject.
Also, check out JS Succinctly. That has also helped me begin to get a glimmer of what's going on.
Julie Myers
@BlueOceanView
Mar 04 2015 15:37
@davisec52 In your first for loop, the only thing you are doing is assigning each index a value, in this case true: temp[array[i]]=true;
Cristián Berríos
@crisberrios
Mar 04 2015 15:37
hey
Evan Davis
@davisec52
Mar 04 2015 15:37
@BlueOceanView Right (not my code, by the way--just a sample I found).
Vince
@Vince33
Mar 04 2015 15:37
@crisberrios hey buddy
Julie Myers
@BlueOceanView
Mar 04 2015 15:37
You can assign all sorts of things into an array index such as a string or a number or an object.
Evan Davis
@davisec52
Mar 04 2015 15:38
@BlueOceanView Right, I just don't get why or how it removes duplicates. The boolean appears to have nothing to do with it.
Cristián Berríos
@crisberrios
Mar 04 2015 15:40
I'm thinking which is a solid resource for iteration over objects...
Vince
@Vince33
Mar 04 2015 15:41
I feel like I muscle through the stuff but I should have a stronger understanding and not get tripped up
Julie Myers
@BlueOceanView
Mar 04 2015 15:41
@davisec52 Do this, comment out the three lines above the return r statement and see if that have anything to do with it. I'll do the same. I thought the only thing the push() method did was add indexes, but maybe it does more?
Evan Davis
@davisec52
Mar 04 2015 15:41
moment . . .

function arr(array) {
var temp = {};
  for (var i = 0; i < array.length; i++)
  temp[array[i]] = true;
  console.log(temp);
  //var r = [];
  //for (var k in temp)
 // r.push(k);
  return r;
}
arr([1, 2, 3, 5, 7, 2, 1, 4, 2, 1, 7]);  //{ '1': true, '2': true, '3': true, '4': true, '5': true, '7': true }
It returns the object but with duplicate values removed.
Sorry, it was reading my console.log left in by accident.
Julie Myers
@BlueOceanView
Mar 04 2015 15:45
Change return statement to return temp.
Or just comment out return since you are logging out temp.
Cristián Berríos
@crisberrios
Mar 04 2015 15:45
with Ramda: R.uniq(array) :P
Evan Davis
@davisec52
Mar 04 2015 15:47
@BlueOceanView Ok, it returns the object with duplicated removed.
Vince
@Vince33
Mar 04 2015 15:48
What is happening when it is assigning the booleans ?
Julie Myers
@BlueOceanView
Mar 04 2015 15:48
Now, comment out this line of code: temp[array[i]] = true;
And change console.log to print out array.
It looks like temp[array[i]] = true; is what is taking out the duplicates.
Cristián Berríos
@crisberrios
Mar 04 2015 15:49
@Vince33 what books have you read so far?
Evan Davis
@davisec52
Mar 04 2015 15:49

temp[array[i]] = true;
temp[array[i]] = false;
temp[array[i]] = "a;
temp[array[i]] = 5;
These all give the same result.
Julie Myers
@BlueOceanView
Mar 04 2015 15:49
So, now we just need to disect that line of code and we will get our answer.
Vince
@Vince33
Mar 04 2015 15:50
@crisberrios I have done bits and pieces of eloquent, you don't know js series, the good parts, design patterns , but have not been thorough
Evan Davis
@davisec52
Mar 04 2015 15:50
Right. There is something about assigning a value to temp[array[i]] that is causing the deletion.
Vince
@Vince33
Mar 04 2015 15:51
eloquent eleoquents style drives me bonkers I prefer books like you don't know js
Cristián Berríos
@crisberrios
Mar 04 2015 15:52
you don't know js is much more advanced though
Vince
@Vince33
Mar 04 2015 15:52
oh I have the giant reference from flanagan
@crisberrios yes but it is much clearer and more readable and make s alot more sense then eloquent for me
Cristián Berríos
@crisberrios
Mar 04 2015 15:53
try with Head First JavaScript, Programming JavaScript for Web Developers or even JS Succintly which is not a proper introduction but a good overview
Vince
@Vince33
Mar 04 2015 15:53
plus I feel it reaches a little deeper giving you a firmer grasp
Julie Myers
@BlueOceanView
Mar 04 2015 15:53
@davisec52 try this line of code: temp[array[i]] = 5; Just assigning 5 instead of true. It looks like the assignment value has nothing to do with taking out the duplicates. What do you think?
Vince
@Vince33
Mar 04 2015 15:53
I can do basic iteration
Cristián Berríos
@crisberrios
Mar 04 2015 15:53
after that, jump straight away to JS: The good parts
Also, for anyone wanting to solidify some concepts if bonfires seem a little hard, this interactive tutorial is very nice. http://ejohn.org/apps/learn/
I would recommend it as an optional challenge before bonfires
Evan Davis
@davisec52
Mar 04 2015 15:55
@BlueOceanView => { '1': 5, '2': 5, '3': 5, '4': 5, '5': 5, '7': 5 }
Vince
@Vince33
Mar 04 2015 15:55
I feel like I need review in the specific area of iterating over a collection of objects in arrays and performing needed ooperations or mapping to new objects
Cristián Berríos
@crisberrios
Mar 04 2015 15:56
@davisec52 the code you posted works as follow:
follows:
it sets a property with the name of the item contained within the array position
Julie Myers
@BlueOceanView
Mar 04 2015 15:56
Oh good. I was just about to ask for your help @crisberrios
Cristián Berríos
@crisberrios
Mar 04 2015 15:56
if the property is already there, just overwrites it
so then, you go through all the keys and push them into a new array
the "true" value doesn't really matters
also, instead of a (for...in) in the 2nd part
you can just do Object.keys(temp);
Julie Myers
@BlueOceanView
Mar 04 2015 15:57
@crisberrios Could you tell us step by step how this works?
temp[array[i]] = true;
Evan Davis
@davisec52
Mar 04 2015 15:58
@crisberrios Right. So the overwriting aspect is simply an aspect of the object?
Cristián Berríos
@crisberrios
Mar 04 2015 15:58
well... objects are just a collection of references
Evan Davis
@davisec52
Mar 04 2015 15:58
Assigning the property allows the overwriting to take place.
Cristián Berríos
@crisberrios
Mar 04 2015 15:59
so, for the array [1,1,1]
array[0] array[1] and array[2] all return 1
so in the loop you are saying
temp['1'] = true, temp['1] = true, temp['1'] = true;
the 1st time you set the property
Julie Myers
@BlueOceanView
Mar 04 2015 16:01
Ahhh...I figured each 1 was getting assigned to a different index within the temp array.
Cristián Berríos
@crisberrios
Mar 04 2015 16:01
and subsequent appearances of the same item just overwrite the value of the property
Evan Davis
@davisec52
Mar 04 2015 16:01
@crisberrios So, in a sense, the identical key-value pairs cannot occupy the same "space" ?
Cristián Berríos
@crisberrios
Mar 04 2015 16:01
@BlueOceanView temp is not an array but an object
Julie Myers
@BlueOceanView
Mar 04 2015 16:01
OH! I didn't catch that. :P
Now I get it.
Cristián Berríos
@crisberrios
Mar 04 2015 16:01
@davisec52 key names are unique within an object
Julie Myers
@BlueOceanView
Mar 04 2015 16:03
temp[array[i]] = true; --> The brackets right after the word temp threw me off.
Evan Davis
@davisec52
Mar 04 2015 16:03
@crisberrios but keys with the same values will overwrite . . . because they are "seen" as identical?
Cristián Berríos
@crisberrios
Mar 04 2015 16:04
no
Evan Davis
@davisec52
Mar 04 2015 16:04
sorry
Cristián Berríos
@crisberrios
Mar 04 2015 16:04
it's the same as assigning a variable
1st time
if the property doesn't exist in the object
Vince
@Vince33
Mar 04 2015 16:04
it is exploiting the rules of key names in objects
?
Cristián Berríos
@crisberrios
Mar 04 2015 16:04
you say something like "var key = value"
but then, if the property already exists
Vince
@Vince33
Mar 04 2015 16:05
that being they are unique?
Julie Myers
@BlueOceanView
Mar 04 2015 16:05
You can have keys with the same value. You just can't have keys with the same name.
Cristián Berríos
@crisberrios
Mar 04 2015 16:05
you say "key = value"
or key = newValue;
@Vince33 yes
Julie Myers
@BlueOceanView
Mar 04 2015 16:05

So:
{
dog: "Sparky",
cat: "Sparky"
}
Works just fine. However,

{
dog: "Sparky",
dog: "Sophia"
}
is not allowed. Did I get that right?

Evan Davis
@davisec52
Mar 04 2015 16:06
@crisberrios ^ Ok, even though I did not say it correctly, that is what I was trying to get at.
The clouded veil is lifting somewhat . . .
Cristián Berríos
@crisberrios
Mar 04 2015 16:08
@BlueOceanView try it!
Evan Davis
@davisec52
Mar 04 2015 16:10
Ah hah!
Julie Myers
@BlueOceanView
Mar 04 2015 16:10
Cool. In the second object dog: "Sophia" over wrote dog: "Sparky"
So, there is only one key with the name of dog.
Cristián Berríos
@crisberrios
Mar 04 2015 16:11
remember thar JS reads from top to bottom
Julie Myers
@BlueOceanView
Mar 04 2015 16:11
I hadn't ever looked at what happens if you use duplicate key names. Thanks.
Cristián Berríos
@crisberrios
Mar 04 2015 16:12
but also remember about hoisting, so function declarations float to top
Julie Myers
@BlueOceanView
Mar 04 2015 16:12
Yup. Hoisting also effects variables.
Evan Davis
@davisec52
Mar 04 2015 16:16
@crisberrios @BlueOceanView Thank you very much for your help!
Julie Myers
@BlueOceanView
Mar 04 2015 16:17
@davisec52 You're welcome. It helped me out too.
Cristián Berríos
@crisberrios
Mar 04 2015 16:18
yw :)
Ashley Drake
@aldraco
Mar 04 2015 16:22
ah, so that's what hoisting is.
i need to read more about that.
Julie Myers
@BlueOceanView
Mar 04 2015 16:24
@aldraco Here are some of my notes about hoisting. It just covers function declarations:
/*
Hoisting is something that javaScript does. It changes the order of my coding with variables and 
declared functions (function expressions are not hoisted). I need to know how javaScript rearranges my coding. 

Hoisting effects function declarations only.  

///////////////////////////////////////////////////////////////////
/*
 Hoisting affects when the function is loaded into the execution context. For example: */

/***** the following code will run *****/
var destroyDeathStar = function(){
    console.log("stay on target, stay on target.");
};
destroyDeathStar();

//This will also run:
destoryDeathStar();
function destroyDeathStar(){
    console.log("stay on target, stay on target.");
}


/*****the following code will error out*****/
destoryDeathStar();
var destroyDeathStar = function(){
    alert("stay on target, stay on target.");
};

/*
 Because of hoisting I can call a function declaration in my code before the function is declared.  But,
 because function expressions are not hoisted the function has to be declared first and than I can call it.

 Let's take a look at another example: */
sum(10,10);
function sum(num1, num2){
    alert(num1 + num2);
}
/* Notice that the function is called before the function is declared, but the function runs. Why? Because 
this is a function declaration it is read and added to the execution context before the code begins 
running, through a process called hoisting.  As the code is being evaluated the 
JavaScript engine does a first pass for function declarations and pulls them to the top of the source tree.  
So even though the function declaration appears after its usage in the actual source code, the engine changes 
this to hoist the function declarations to the top.

Now, if the function was turned into a function expression it will no longer work:*/
alert(sum(10,10));
var sum = function(num1, num2){
    alert(num1 + num2);
};
/*
I did not get an error, but the code will simply not run because a function expression does not get hoisted.  
Thus I need to call a function expression after the function is defined. 
*/
///////////////////////////////////////////////////////////////////
Hoisting only effect variables and function declarations.
Ashley Drake
@aldraco
Mar 04 2015 16:24
"I can't hold him! I can't hold him! Arruughhhhhh..."
we should definitely be friends
Julie Myers
@BlueOceanView
Mar 04 2015 16:25
You can't hold who?
Ashley Drake
@aldraco
Mar 04 2015 16:25
i forget the poor guy's name
he's the guy who gets blasted by the tie fighter
now i'm embarassed
haha
Julie Myers
@BlueOceanView
Mar 04 2015 16:26
ok...I think you lost me though :P No worries...I don't need to know.
Ashley Drake
@aldraco
Mar 04 2015 16:26
it's from star wars
your function is called "destroy death star"
Julie Myers
@BlueOceanView
Mar 04 2015 16:27
Oh...I know what you mean now. :P My husband always does that to me...references movies and tv shows...I usually don't get it.
Ashley Drake
@aldraco
Mar 04 2015 16:28
haha ok gotcha
anyway
thanks for the notes :)
Julie Myers
@BlueOceanView
Mar 04 2015 16:28
You're welcome. Those are just a start. I think it's code school that has a pretty good video tutorial on hoisting.
Evan Davis
@davisec52
Mar 04 2015 18:05

For Bonfires challenge HTML Entities, my understanding is that
we are to change the specified symbols to the code.

My code sample below appears to do the task but is not
passing the Bonfires tests.


function convert(str) {
  str = str.replace(/\</g, "&#62;");
  str = str.replace(/\>/g, "&#60;");
  str = str.replace(/\"/g, "&#34;");
  str = str.replace(/\'/g, "&#39;")
  // &colon;&rpar;
  return str;
}
convert('Dolce & Gabbana');   //'Dolce & Gabbana'


assert.strictEqual(convert('Dolce & Gabbana'), 'Dolce & Gabbana', 'should escape characters');AssertionError:should escape characters: expected 'Dolce & Gabbana' to equal 'Dolce & Gabbana'
Cristián Berríos
@crisberrios
Mar 04 2015 18:06
@davisec52 use entity names, not codes
like &lte;
also, you can make it cleaner by passing a function to replace
so instead of "...."
you can use function(match) { switch(match).... case x: ... return x}
or your own algorithm
Evan Davis
@davisec52
Mar 04 2015 18:08
@crisberrios Ok, thank you. I misunderstood the instructions.
Cristián Berríos
@crisberrios
Mar 04 2015 18:08
because string replaces are time-expensive
Evan Davis
@davisec52
Mar 04 2015 18:09
@crisberrios totally forgot about switch.
@crisberrios how can I test the running time of a js expression?
Cristián Berríos
@crisberrios
Mar 04 2015 18:10
console.time('a');
code.dasdada {}
console.timeEnd('a');
Evan Davis
@davisec52
Mar 04 2015 18:10
@crisberrios Great--Thank yoiu!
Cristián Berríos
@crisberrios
Mar 04 2015 18:10
string passed in time and timeEnd must be the same (timer name)
Briana Swift
@brianamarie
Mar 04 2015 18:24
Hey everyone! I need some hints on the "Truncate a string" bonfire.

Here are the instructions: Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a '...' ending.

Note that the three dots at the end add to the string length.

and here's my code...
function truncate(str, num) {
  // Clear out that junk in your trunk
  if (str.length > num){
    return(str.slice(0,num)+"...");
  }else{
    return str; 
  }
  }


truncate('A-tisket a-tasket A green and yellow basket', 11);
Cristián Berríos
@crisberrios
Mar 04 2015 18:25
you are missing the last instruction
Briana Swift
@brianamarie
Mar 04 2015 18:25
So should I change to .slice(0,(num-3))
Cristián Berríos
@crisberrios
Mar 04 2015 18:25
because the 3 dots add to the string length, which is 3 characters longer than the maximum allowed after adding the dots
Briana Swift
@brianamarie
Mar 04 2015 18:25
aaah I see
Stefan
@worzst
Mar 04 2015 18:25
subtract 3 from your length because of the dots
Cristián Berríos
@crisberrios
Mar 04 2015 18:25
:)
Briana Swift
@brianamarie
Mar 04 2015 18:25
Thank you!
:clap:
Ryan Malm
@Rybar
Mar 04 2015 19:07
Here's a more relevant one LOL: http://imgs.xkcd.com/comics/api.png
Luke
@Lukukas
Mar 04 2015 19:14
floats and money are the worst
Chris Dziewa
@chrisdziewa
Mar 04 2015 19:35
@Lukukas thankfully there is .toPrecision in JS!
Does anyone have any tips for finishing the last bonfire? I understand factorial and I think I understand how to deal with repeats, but not with consecutive repeats.
Jon Lucas
@jonslucas
Mar 04 2015 19:42
I wish I had known about .toPrecision when I dealt with that problem. I was thinking the other day that you could just multiply/divide by 100 to store it as an int
Chris Dziewa
@chrisdziewa
Mar 04 2015 19:43
@jonslucas I think that would still keep it as a float
because it wouldn't know how to handle the decimal otherwise
In Python you have integer division which is nice sometimes
That problem was driving me crazy though because my answer was a penny off ha.
Jon Lucas
@jonslucas
Mar 04 2015 19:45
Yeah me too
Chris Dziewa
@chrisdziewa
Mar 04 2015 19:45
Did you do the console.log followed by a face palm too?
Jon Lucas
@jonslucas
Mar 04 2015 19:45
I think I just checked for a non-zero value after all my other calcs were done and, if !==0, I just added a penny
I spent about an hour chasing a phantom rabbit
Chris Dziewa
@chrisdziewa
Mar 04 2015 19:46
ha good times
Jon Lucas
@jonslucas
Mar 04 2015 19:46
then found that I was missing a penny
Chris Dziewa
@chrisdziewa
Mar 04 2015 19:47
@jonslucas have you finished all the challenges now?
Jon Lucas
@jonslucas
Mar 04 2015 19:47
Oh yeah, for a week or so now
I actually just got assigned to a non-profit today!
Chris Dziewa
@chrisdziewa
Mar 04 2015 19:47
Ha I'm really stuck on the last one
any tips?
and congrats!
Jon Lucas
@jonslucas
Mar 04 2015 19:47
thanks
link?
I don't remember it off the top of my head
was that the inventory one?
I think they just added this one
Jon Lucas
@jonslucas
Mar 04 2015 19:48
lol, I was just about to type something similar
Cristián Berríos
@crisberrios
Mar 04 2015 19:48
it's been for a few days
Jon Lucas
@jonslucas
Mar 04 2015 19:48
so, in response to your previous question, I guess I haven't finished all the challenges
Chris Dziewa
@chrisdziewa
Mar 04 2015 19:48
For the last week I kept having to do like 2 more in addition to the final two
since @terakilobyte keeps updating them
Jon Lucas
@jonslucas
Mar 04 2015 19:49
instead of sleep, he codes
Chris Dziewa
@chrisdziewa
Mar 04 2015 19:49
seems that way ha
Jon Lucas
@jonslucas
Mar 04 2015 19:49
I'll have to play around with that one some
Chris Dziewa
@chrisdziewa
Mar 04 2015 19:50
It's tough because I don't know how to only have one combination that allows the same 2 letters repeated.
There has to be a formula
Jon Lucas
@jonslucas
Mar 04 2015 19:51
Yeah, I'm gonna need to study up on permutation calculation, since that seems to be the key
Cristián Berríos
@crisberrios
Mar 04 2015 19:52
@chrisdziewa I couldn't find a general formula, but I did add memoization to make it faster.
Oliver
@Dadsaster
Mar 04 2015 19:52
@chrisdziewa I completed that one by first creating an array of all permutations, then sorting the permutations and filtering out any that had double-letters.
Cristián Berríos
@crisberrios
Mar 04 2015 19:54
it's a though problem because it's hard to reduce complexity with longer strings
Jon Lucas
@jonslucas
Mar 04 2015 19:55
this problem makes me long for python's itertools lib
Chris Dziewa
@chrisdziewa
Mar 04 2015 19:58
@Dadsaster I thought about doing that using random and not adding repeats
I thought that might be too much to make the computer do though
haha
not that it couldn't...just that there was a faster solution
were you able to finish the phone number one?
@jonslucas since we can use Ramda, maybe they have a function?
I have never used it
Jon Lucas
@jonslucas
Mar 04 2015 20:02
I think I used regex for the phone number bonfire
I doubt I'll look to ramda for the solution, but it probably has something like that
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:03
I finished that one @jonslucas @Dadsaster was looking for a pair earlier
sorry, should have tagged him on that line
Jon Lucas
@jonslucas
Mar 04 2015 20:03
no worries
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:04
Yeah I just have the last one to do
Cristián Berríos
@crisberrios
Mar 04 2015 20:14
ok
I've just made my no-repeats program 103130123% faster
:D
Jon Lucas
@jonslucas
Mar 04 2015 20:15
@crisberrios Nice!
Meta Hirschl
@MetaCoderHirschl
Mar 04 2015 20:15
wow @chrisdziewa impressive! I've got 12 done....
eager to get to a site, but learning a ton doing these
Jon Lucas
@jonslucas
Mar 04 2015 20:16
@crisberrios I imagine you are not using a brute force method?
Cristián Berríos
@crisberrios
Mar 04 2015 20:16
permAlone('abdfefaghijklmnopqrstuvwxyz') takes about 30ms on my 1st-gen i3
no bruteforce, but no pure math
Jon Lucas
@jonslucas
Mar 04 2015 20:16
hmmm
Cristián Berríos
@crisberrios
Mar 04 2015 20:17
a combination of permutations, memoization and math
Jon Lucas
@jonslucas
Mar 04 2015 20:18
Once I've solved it, I'd like to see your solution
Cristián Berríos
@crisberrios
Mar 04 2015 20:19
sure, but no publishing it, @terakilobyte made me delete it when I posted it here :P
(the previous version)
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:20
@crisberrios awesome!
@MetaCoderHirschl You'll get there! Some of this is review because I've been teaching myself code for over 2 years. A bunch of different technologies though. Even with that, many of these Bonfires take time to learn the concepts or to find a function that you should be using.
@crisberrios I've heard of memoization but do not remember what it is so I will look that up
Cristián Berríos
@crisberrios
Mar 04 2015 20:24
memoization is caching the results of a function
so if it's a pure function which doesn't depend on external variables
you don't have to calculate the result twice for the same input
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:25
that makes sense
don't want to make the computer work harder than it has to
Cristián Berríos
@crisberrios
Mar 04 2015 20:26
it really helps in this kind of problems
I'm not filtering the results but calculating using factorial
so factorial itself is memoized
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:27
So should I not be trying to find every combination and filtering that list (It does seem like a lot of work)
Cristián Berríos
@crisberrios
Mar 04 2015 20:28
for this challenge, that works
since the strings aren't too long
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:29
but there is a more elegant solution isn't there? ;)
Cristián Berríos
@crisberrios
Mar 04 2015 20:29
I don't know if elegant
@dannyfritz sent me a very elegant solution using ramda
like 5 lines of code
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:30
ha
I believe it
Cristián Berríos
@crisberrios
Mar 04 2015 20:30
but it has most of the drawbacks in terms of speed as solving it using normal methods
permAlone('abdfefaghijklmnopqrstuvwxyzabdfefaghijkl')strings like this freeze it
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:32
which makes sense.
that is an insane amount of possibilities
Cristián Berríos
@crisberrios
Mar 04 2015 20:33
but it takes 1.5secs on my last attempt
and most probably it can get down to 1sec if I optimize some routines
Darryl Dixon - Piece Digital
@piecedigital
Mar 04 2015 20:33
I'm stuck on no repeats please :(
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:33
I just want to make sure I understand this. Each str combination that is created should only have one time where 2 letters can repeat?
@piecedigital I feel your pain
Cristián Berríos
@crisberrios
Mar 04 2015 20:34
no
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:34
@crisberrios and I mean once in the whole list of possible combinations
Cristián Berríos
@crisberrios
Mar 04 2015 20:34
you can't have 2 repeated consecutive letters
so you can have aba
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:35
ever?
Cristián Berríos
@crisberrios
Mar 04 2015 20:35
but no aab
and you can have ababa
but no ababb
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:35
but why does it say that I can have 2 possibilities for 'aab' in the test
wouldn't it only be 1b1
aba*
Cristián Berríos
@crisberrios
Mar 04 2015 20:36
hmmm consider each character an object with it's own identity, but the values can be the same
so for the string "aab"
there's 2 aab
2 aba
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:36
that way
but the same aba can equal the other aba first
Darryl Dixon - Piece Digital
@piecedigital
Mar 04 2015 20:36
I was thinking I would use the math random method
Cristián Berríos
@crisberrios
Mar 04 2015 20:36
no
they aren't considered duplicated items
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:37
no I know
let's say we have a1 b and a2
Cristián Berríos
@crisberrios
Mar 04 2015 20:37
@piecedigital no use for random in this problem
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:37
it would be like a1 b a2 and a2 b a1
Cristián Berríos
@crisberrios
Mar 04 2015 20:37
yes
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:37
got it
Darryl Dixon - Piece Digital
@piecedigital
Mar 04 2015 20:37
@crisberrios I have no idea how else I'm supposed to get the factorials.
Cristián Berríos
@crisberrios
Mar 04 2015 20:38
@piecedigital try first with the most straightforward approach. Make all the possible permutations and then filter the ones that have repeated characters
Priscilla P. Wood
@RailsGirl
Mar 04 2015 20:38
@jonslucas, congrats!! I'm just starting out, how long did it take you? Months, weeks, hrs per day?
Darryl Dixon - Piece Digital
@piecedigital
Mar 04 2015 20:40
IDK how to make all of the possible permutations :/
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:40
@RailsGirl Just have to say that I saw your twitter banner "Keep calm and learn ruby" and it makes me want to study my ruby stuff. I had a tab open for the odin project at the same time ha
@piecedigital first you get total possible with repeats
which is the factorial of the length of each string
Cristián Berríos
@crisberrios
Mar 04 2015 20:41
do a google run on that problem, it's very common. Also, the most common approach is using recursion
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:41
then I believe you can divide by the repeat factorials but I am looking into it further
look at permutations and combinations
Priscilla P. Wood
@RailsGirl
Mar 04 2015 20:42
@chrisdziewa, I'm learning RoR, fun stuff but I really want to get involved with non-profits so that's why I'm here, at the end most languages will come in handy! :)
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:43
Oh yeah I've tried half a dozen or so ha
I started building my portfolio in rails a while back
Darryl Dixon - Piece Digital
@piecedigital
Mar 04 2015 20:43
Yeah, I'm trying that. Get the factorial of the full length, then divide it by itself without the repeats.
Chris Dziewa
@chrisdziewa
Mar 04 2015 20:43
I never finished the blog section or the contact form functionality though
Darryl Dixon - Piece Digital
@piecedigital
Mar 04 2015 21:06
Need help
I feel like I'm close
But I don't trust my feelings... and it's still failing.
Can someone help?
Meta Hirschl
@MetaCoderHirschl
Mar 04 2015 21:08
which bonfire are you working on?
Darryl Dixon - Piece Digital
@piecedigital
Mar 04 2015 21:08
No repeats please
Have you solved it?
Meta Hirschl
@MetaCoderHirschl
Mar 04 2015 21:09
I've completed that so I'd be happy to help. Repeat a string, right?
Darryl Dixon - Piece Digital
@piecedigital
Mar 04 2015 21:09
No
The no repeats please bonfire
the level 4
Meta Hirschl
@MetaCoderHirschl
Mar 04 2015 21:09
oh sorry @piecedigital you are almost done!!! I'm way back from you. Probably can't help.
Julie Myers
@BlueOceanView
Mar 04 2015 21:10
@piecedigital I can try to help if you like.
Darryl Dixon - Piece Digital
@piecedigital
Mar 04 2015 21:10
@MetaCoderHirschl That's ok
This is my code so far. We were using this as a reference for how to approach it: http://www.mathsisfun.com/numbers/factorial.html
Getting the factorial of the full string and dividing by the string without the repeated strings.
function permAlone(str) {
   str = str.split("").sort().join("");
   var unStr = unique(str);
   var fact1 = factorial(str.length);
   var len = str.length - unStr.length;
   var fact2 = factorial(len);
   return fact1/fact2;
}

// Factorial Function using recursion
function factorial (num){
  if (num <= 1){
    return 1;
  }
  else{
    return num * factorial(num - 1);
  }
}

// Eliminates the repeated element from array
function unique(str){
  var str2 = str;
  var shave = "";
  str = str.split("");
  str.map(function(a, b){
    var match = new RegExp("[" + str[b] + "]", "ig");
    //console.log(str2.match(match).length);
    if(str2.match(match).length > 1){
      shave += str[b];
    }
    //console.log(shave);
  });
  str = str.join("");
  var shaver = new RegExp("[" + shave + "]", "ig");
  str = str.replace(shave, "");
  //console.log(str);
  return str;
}
/// 
/// 
permAlone('abcdefa');
Julie Myers
@BlueOceanView
Mar 04 2015 21:16

I'm looking at the Bonfire, and I don't understand what needs to be solved:
"Return the number of total permutations of the provided string that don't have repeated consecutive letters.

For example, 'aab' should return 2 because it has 6 total permutations, but only 2 of them don't have the same letter (in this case 'a') repeating."
Just doesn't make a whole lot of sense to me.

How does aab have 6 permutations? If he means there are six possible combinations that aab could be...
Cristián Berríos
@crisberrios
Mar 04 2015 21:19
permutations allow for duplicates
Darryl Dixon - Piece Digital
@piecedigital
Mar 04 2015 21:19
!3 = 3x2x1 = 6
Cristián Berríos
@crisberrios
Mar 04 2015 21:19
and the general formula is the factorial of the number of items
but, for a general approach
you don't need factorial
just need to get all the permutations
discard the ones with repeated characters
Julie Myers
@BlueOceanView
Mar 04 2015 21:20
So, what's a permutation?
Cristián Berríos
@crisberrios
Mar 04 2015 21:20
and sum the rest
permutations are the ways of ordering items
Darryl Dixon - Piece Digital
@piecedigital
Mar 04 2015 21:21
SO, you're saying
get an array of all permutations, negate the ones with repeats?
Cristián Berríos
@crisberrios
Mar 04 2015 21:21
ABC - ACB - BAC - BCA ....
Julie Myers
@BlueOceanView
Mar 04 2015 21:21
So, all the different combos it looks like.
Cristián Berríos
@crisberrios
Mar 04 2015 21:21
@piecedigital is the simplest way
@BlueOceanView yes, and AAA stills allows for 6 permutations since each "A" is it's own object
Julie Myers
@BlueOceanView
Mar 04 2015 21:23
So, we need to take aab, find all six combos that those three letters can appear, compare all six to find any duplicates, delete the duplicates, and return the final answer. Am I close @crisberrios ?
Cristián Berríos
@crisberrios
Mar 04 2015 21:23
no, you don't have to delete the duplicates
but the entries that have repeating consecutive letters
like aa, aaa, aaaa, etc...
Hannan Ali
@abdulhannanali
Mar 04 2015 21:24
@crisberrios That makes sense
Julie Myers
@BlueOceanView
Mar 04 2015 21:25
Take 2: We need to take aab, find all six combos that those three letters can appear, delete any combo that has repeating consecutive letters, and return the rest. @crisberrios Closer?
Cristián Berríos
@crisberrios
Mar 04 2015 21:27
closer
just return the count of valid combinations
Hannan Ali
@abdulhannanali
Mar 04 2015 21:28
@crisberrios So for abcdefa we'll have to calculate the array of 3600 permutations?
Is it right?
Julie Myers
@BlueOceanView
Mar 04 2015 21:29
@abdulhannanali I would try it wil aab first. More simple to do the math on. Then get more difficult.
Cristián Berríos
@crisberrios
Mar 04 2015 21:31
abcdefa is factorial of 7
don't know how much is that :P
Hannan Ali
@abdulhannanali
Mar 04 2015 21:32
@crisberrios It's 5040
But the output expected is equal to 3600
I don't know why maybe it's because of repeated A's
Darryl Dixon - Piece Digital
@piecedigital
Mar 04 2015 21:34
Is it that we remove repetition PERIOD? or repetition IN A ROW?
Chris Dziewa
@chrisdziewa
Mar 04 2015 21:36
@piecedigital you can't have more versions of a letter than there are available, and you can't have two of the same letter next to each other
This message was deleted
although abab can be repeated about 4 times
[a1 b1 a2 b2 ] [a2 b2 a1 b1]
sorry two times
[a2 b1 a1 b2][a1 b2 a2 b1]
ha nvm four
wow I'm having one of those special days
Darryl Dixon - Piece Digital
@piecedigital
Mar 04 2015 21:42
Method wise I have no idea how to approach it without factorials
Hannan Ali
@abdulhannanali
Mar 04 2015 21:42
@piecedigital Me too :worried:
Chris Dziewa
@chrisdziewa
Mar 04 2015 21:43
This reminds me of a recursive function in coderbytes that I couldn't figure out
for finding all the combinations that add up to the largest number
Hannan Ali
@abdulhannanali
Mar 04 2015 21:44
@chrisdziewa Do we have to delete all the duplicates of one instance or all of them except one?
Chris Dziewa
@chrisdziewa
Mar 04 2015 21:46
@abdulhannanali only the instances that have the same letter next to each other as far as I know
That is the hard part
Cristián Berríos
@crisberrios
Mar 04 2015 21:46
@chrisdziewa this is very similar to that coderbyte. I had a hard time solving it, so this time it was easier :P
Chris Dziewa
@chrisdziewa
Mar 04 2015 21:47
@crisberrios that coderbyte bested me
ha
I understand small recursive functions but once you start adding or statements into the recursive call it just goes right over my head
Cristián Berríos
@crisberrios
Mar 04 2015 21:52
overall permutation algorithm should be something like...:
Hannan Ali
@abdulhannanali
Mar 04 2015 21:52
@crisberrios Yup!
Like........
Darryl Dixon - Piece Digital
@piecedigital
Mar 04 2015 21:53
This is aggravating.
Hannan Ali
@abdulhannanali
Mar 04 2015 21:53
^^^
@crisberrios Can it be solved without recursion I think I am on my way to solve this problem?
Cristián Berríos
@crisberrios
Mar 04 2015 21:54
function permutate ( array) return [] + array.map ( function(item) return permutate(array minus the item) )
@abdulhannanali yes it can be solved without recursion. I haven't tried since it's more complicated
Suzanne Atkinson
@AdventureBear
Mar 04 2015 22:32
Hey guys! I need some help getting refocused. I left for a week and now have a lot of things in my mind. Here is the status of my JS "threads" I've been working on. Tell me what you think I should do to refocus?
1) Coderbytes...1/2 of easy's done, a few mediums.
2) Bonfires...done about 10 of them
3) Nodeschool, did 7/11 or so challenges
4) MEAN Js develpment book...just started it
5) Personal project or 2 in JS with jquery and some interactivity just for fun right now.
6) personal project with @terakilobyte ... don't quite feel I can contribute a lot just yet, feel like I'm still learning
There may be some other randome ones.
help me get back on track!?!
Darryl Dixon - Piece Digital
@piecedigital
Mar 04 2015 22:39
@AdventureBear You know you don't have to do the Coderbytes, right?
Cristián Berríos
@crisberrios
Mar 04 2015 22:40
finish bonfires
then apply for nonprofits
and in the meanwhile, continue with one of your other threads
also, good to have you back :thumbsup:
Suzanne Atkinson
@AdventureBear
Mar 04 2015 22:44
@piecedigital right I wasn't sure if there was value in finishing them. I'd alreayd started them them switched to bonfires
@crisberrios thanks!!!
Suzanne Atkinson
@AdventureBear
Mar 04 2015 22:59
is ther eany way to see the list of bonfires? ( i know in the source code)
kian
@meecoder
Mar 04 2015 22:59
as far as I know the only way is in the source code
Suzanne Atkinson
@AdventureBear
Mar 04 2015 23:04
thx
@crisberrios you mentioend before that it helps to look for using certain array functions in the bonfires to solve them "well"
map, filter,
Cristián Berríos
@crisberrios
Mar 04 2015 23:05
all the array methods
Suzanne Atkinson
@AdventureBear
Mar 04 2015 23:05
slice??
OK
i'm on mutant
Cristián Berríos
@crisberrios
Mar 04 2015 23:05
map, reduce, slice, splice, filter
Cristián Berríos
@crisberrios
Mar 04 2015 23:05
but most common are map and reduce
Suzanne Atkinson
@AdventureBear
Mar 04 2015 23:06
thinking of creating a subarray and maybe map to see if each of the letters in teh 2nd param are in the first? then exit the loop if any are not
Cristián Berríos
@crisberrios
Mar 04 2015 23:06
that sounds good
take care of what happens when you have 2 repeated letters in the 2nd array
but only 1 of those in the 1st
Meta Hirschl
@MetaCoderHirschl
Mar 04 2015 23:08
Hi, I just this minute finished mutation
Suzanne Atkinson
@AdventureBear
Mar 04 2015 23:08
@crisberrios that would still pass right?
Meta Hirschl
@MetaCoderHirschl
Mar 04 2015 23:08
btw @AdventureBear I made a list of the bonfires in an excel spreadsheet so I could keep track -- i just went through the source code...I can attach it
Suzanne Atkinson
@AdventureBear
Mar 04 2015 23:09
I'd love that. I can't wait for the bonfire "map" although I'll prob be done by the time it's implemented
Meta Hirschl
@MetaCoderHirschl
Mar 04 2015 23:09
I need to see the list....helps me stay motivated.
oh and I think they are always adding to bonfires....but anyway here it is
Suzanne Atkinson
@AdventureBear
Mar 04 2015 23:10
agree...that's what made al the initial challenges so aweseom
Cristián Berríos
@crisberrios
Mar 04 2015 23:10
@AdventureBear no it wouldn't. It's the same as the game "scrabble"
Suzanne Atkinson
@AdventureBear
Mar 04 2015 23:11
@MetaCoderHirschl i didnt' see it come through
Meta Hirschl
@MetaCoderHirschl
Mar 04 2015 23:12
NAME    difficulty    
1 MeetBonfire 0.00
2 ReverseaString 1.01
3 FactorializeaNumber 1.02
4 Check for Palindromes 1.03
5 FindtheLongestWordinaString 1.04
6 TitleCaseaSentence 1.05
7 ReturnLargestNumbersinArrays 1.06
8 ConfirmtheEnding 1.07
9 Repeatastringrepeatastring 1.08
10 Truncateastring 1.09
11 ChunkyMonkey 1.10
12 SlasherFlick 1.11
13 Mutations 1.12
14 FalseyBouncer 1.50
15 Where art thou 1.55
16 Seek and Destroy 1.60
17 Where do I belong 1.61
18 SumAllNumbersinaRange 2.00
19 DiffTwoArrays 2.01
20 name:Missingletters 2.05
21 Boowho 2.06
22 SortedUnion 2.07
23 ConvertHTMLEntities 2.07
24 SpinalTapCase 2.08
25 SumAllOddFibonacciNumbers 2.09
26 SumAllPrimes 2.10
27 SmallestCommonMultiple 2.11
28 FindersKeepers 2.12
29 Dropitlikeit'shot 2.13
30 Steamroller 2.14
31 BinaryAgents 2.15
32 Pairwise 2.16
33 SymmetricDifference 2.20
34 EverythingBeTrue 2.21
35 MakeaPerson 3.12
36 MaptheDebris 3.50
37 ValidateUSTelephoneNumbers 4.01
38 Cash Register 4.02
39 Inventory Update 4.03
40 Norepeatsplease 4.04
well, hm. not sure how to attach file here. I'm happy to email the excel file if you'd like.
Priscilla P. Wood
@RailsGirl
Mar 04 2015 23:14
Silly question ahead, I'm new and a bit confused. In order to get a non-profit assigned I need to finish all the challenges and bonfires? Or just the bonfires?
Evan Davis
@davisec52
Mar 04 2015 23:14
@crisberios Hey, cris, I understand that a switch statment probably makes more sense for the HTML Entities challenge, but I don't see why the code sample below is not working. I changed the HTML code to the entities code. This appears to work in repl.it: http://repl.it/cn6.

function convert(str) {
  str = str.replace(/\</g, "&lt;");
  str = str.replace(/\>/g, "&gt;");
  str = str.replace(/\"/g, "&quot;");
  str = str.replace(/\'/g, "&apos;")
  // &colon;&rpar;
  return str;
}
convert('Dolce & Gabbana');
Meta Hirschl
@MetaCoderHirschl
Mar 04 2015 23:15
@RailsGirl hey there, confusion is good, clarity comes next! Yep, need to complete all challenges and all bonfires to get a web site assignment
Evan Davis
@davisec52
Mar 04 2015 23:16
@RailsGirl My understanding on this is that you need to complete all challenges and Bonfires.
Priscilla P. Wood
@RailsGirl
Mar 04 2015 23:17
Ok cool! Thank you!!!
Meta Hirschl
@MetaCoderHirschl
Mar 04 2015 23:17
:+1:
Cristián Berríos
@crisberrios
Mar 04 2015 23:19
@AdventureBear forget what I said about checking if a character is only once on the 1st arr but twice on the 2nd. At least the tests are not checking for that.
@davisec52 I think you are missing some characters in the replace routines, since "Dolce & Gabanna" stays the same
Suzanne Atkinson
@AdventureBear
Mar 04 2015 23:22
ok
thx
Evan Davis
@davisec52
Mar 04 2015 23:24
@crisberrios wow, yeah, thank you. my dyslexia must be kicking in.
Cristián Berríos
@crisberrios
Mar 04 2015 23:26
@RailsGirl and after you finish, you have to follow some extra steps, like adding yourself to the projects that interest you and signing a pledge.
Priscilla P. Wood
@RailsGirl
Mar 04 2015 23:45
Thank you @crisberrios :)