These are chat archives for FreeCodeCamp/HelpJavaScript

8th
Sep 2017
Andrew Kay
@andrewjkay
Sep 08 2017 00:00
@Hijerboa a for loop without checking even numbers or numbers that are multiples of those already checked
or a hash of some kind
Nick Cleary
@Hijerboa
Sep 08 2017 00:02
@andrewjkay hmm thats not a bad idea
luccifer00
@luccifer00
Sep 08 2017 00:18
hi there!
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 00:19
Sup
luccifer00
@luccifer00
Sep 08 2017 00:20
 var rank1=[];
  var file1=[];

    for(var i=0;i<input;i++){
      rank1+= String.fromCharCode(i+65);
    file1+= parseInt(i+1);
  }
how can i get file1 return a [1,2,3,4,5....] , only can get a string as "12345..."
i use parseInt to change the number in string to a number... but i also return the "12345...."string
Nick Cleary
@Hijerboa
Sep 08 2017 00:21
@luccifer00 use .split("");
that will divide it at each number
luccifer00
@luccifer00
Sep 08 2017 00:24
yep, but still divide as string ["1","2","3","4"...]
anyways i was cheking the console.log wrong, so i can try new posibilities... i was a mistake as console.log(file1).Split("); lol thanks @Hijerboa
CamperBot
@camperbot
Sep 08 2017 00:25
:cookie: 285 | @hijerboa |http://www.freecodecamp.com/hijerboa
luccifer00 sends brownie points to @hijerboa :sparkles: :thumbsup: :sparkles:
Nick Cleary
@Hijerboa
Sep 08 2017 00:26
@camperbot np mate
Hey can anyone explain to me how this has an infinite loop?
function sumPrimes(num) {
    var isPrime = true;
    var counter = 1;
    var sum = 0;
    while(counter <= num){
      if(counter >= 3){
        for(i=3; i<=(counter/2); i+2){
          if(Number.isInteger((counter/i))){
            isPrime = false;
            i = ((counter/2)+1);
          } else {
            isPrime = true;
          }
        }
      } else if(counter >= 2){
        isPrime = false;
      }
      if(isPrime){
        sum += counter;
        counter++;
      }else{
        counter++;
      }
    }
    return sum;
  }
FCC says there's an infinite loop at the if(counter >= 3) part
Coy Sanders
@coymeetsworld
Sep 08 2017 00:39
your for loop has a bug
@Hijerboa
Nick Cleary
@Hijerboa
Sep 08 2017 00:40
@coymeetsworld does it have to do with the statement i<=(counter/2) ?
Coy Sanders
@coymeetsworld
Sep 08 2017 00:40
no
the logic looks complicated though, i don't like that you are modifying i in other places, it opens yourself to bugs
Nick Cleary
@Hijerboa
Sep 08 2017 00:41
ohhhhh its the i+2
it should be i+=2... corrrect?
Coy Sanders
@coymeetsworld
Sep 08 2017 00:41
yes
but the other times you may change i could cause issues too
there may be an inf loop there too
i would rethink this
Nick Cleary
@Hijerboa
Sep 08 2017 00:41
ok... Legitimate question: how else would I break out of the for loop?
or should i not use a for loop at all?
because thats the only way i can think of to test for primes
Manish Giri
@Manish-Giri
Sep 08 2017 00:45
@Hijerboa return inside a for loop would terminate it..
Gersho
@Gersho
Sep 08 2017 00:46
wouldn't that stop the function too ?
Nick Cleary
@Hijerboa
Sep 08 2017 00:46
@Manish-Giri as @Gersho it would stop the function... and im trying to add all primes for one of the challenge
Coy Sanders
@coymeetsworld
Sep 08 2017 00:47
use break to break out of the loop
Manish Giri
@Manish-Giri
Sep 08 2017 00:47
then use break
besides, I did say "terminate", didn't I?
Gersho
@Gersho
Sep 08 2017 00:47
you did, but it terminates more than intended :P
Nick Cleary
@Hijerboa
Sep 08 2017 00:48
@coymeetsworld @Manish-Giri I honeslty had no idea break existed....
Manish Giri
@Manish-Giri
Sep 08 2017 00:48
terminate was meant as terminate the function.
Gersho
@Gersho
Sep 08 2017 00:48
break and continue are both keyword usable within a loop @Hijerboa
Nick Cleary
@Hijerboa
Sep 08 2017 00:48
@Gersho @Manish-Giri @coymeetsworld TIL... thanks guys
CamperBot
@camperbot
Sep 08 2017 00:48
hijerboa sends brownie points to @gersho and @manish-giri and @coymeetsworld :sparkles: :thumbsup: :sparkles:
:cookie: 404 | @gersho |http://www.freecodecamp.com/gersho
:star2: 3000 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
:star2: 6512 | @manish-giri |http://www.freecodecamp.com/manish-giri
Gersho
@Gersho
Sep 08 2017 00:49
@coymeetsworld 3k, congratulation
Manish Giri
@Manish-Giri
Sep 08 2017 00:49
woot woot, congrats @coymeetsworld
:tada:
Coy Sanders
@coymeetsworld
Sep 08 2017 00:49
:ok_hand: only took like 2 months since 2990 lol
Manish Giri
@Manish-Giri
Sep 08 2017 00:49
lol
Coy Sanders
@coymeetsworld
Sep 08 2017 00:49
then again i was on vacation pretty much all last month
Adam Faraj
@adamfaraj
Sep 08 2017 01:44
hey guys
Gersho
@Gersho
Sep 08 2017 01:44
:wave: @adamfaraj
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 01:45
Sup
Adam Faraj
@adamfaraj
Sep 08 2017 01:45
got a quick issue i'm trying to fix
nvm, got it
haha
Gersho
@Gersho
Sep 08 2017 02:28
CodeAcademy's React lessons are nice, but i'm getting tired of copy pasting document.getElementById('app')
luccifer00
@luccifer00
Sep 08 2017 02:36
hie there! i would like to créate a function for créate an ordered list based on letters, A-Z, so the next after Z should be AA, AB, .... and After ZZ, should be AAA, AAB, and so on....
for(var i=0;i<input;i++){
    var letter=String.fromCharCode(i+65);
      if(letter> 91){
        function add(first,scnd){

        }
      }
i have this start, but i dont know how to realice at all...
Bryan Reese
@breese8009
Sep 08 2017 02:39
so i got 2 functions, one is rendering, the other at this point I just want to get the exact data-id everytime i click on a .list-group-item but i only get the first one right then it will just keep logging that one over an over...
function renderListStyle(style) {

    let styleHtml=`
    <a href="#" class="list-group-item list-group-item-action" data-id="${style._id}">${style.type}</a>
    `
    $('.list-group-style').prepend(styleHtml);

}




function activeStyles(e) {
    let styleId = $(this).find('a').attr('data-id');
    console.log(styleId)


}
Claudio Restifo
@Marmiz
Sep 08 2017 02:45
@breese8009 have you tried with the data function?
(this).data('id')
Bryan Reese
@breese8009
Sep 08 2017 02:45
@Marmiz wouldnt that give me the same thing?
as what im getitng with styleId
or no?
ill try it real quick an let u kno for sure
lol
@Marmiz gave me same thing
Claudio Restifo
@Marmiz
Sep 08 2017 02:53

@breese8009 anyway I would refactor the render as so:
I would add a onclick listener directly on the a that call a methods that gives you back the data.

So far how are you listening for the activeStles()?

Bryan Reese
@breese8009
Sep 08 2017 04:11
@Marmiz i hadnt gotten there yet, i was tying to get the id to come up on the element i click
but for some reason when i click act like i clicked an its actin like a div got clicked
ah i cant type
i give up lol
Bryan Reese
@breese8009
Sep 08 2017 04:22
i solved it
add 2nd arg to click event
$('.list-group-style').on('click', '.list-group-item', activeStyles)
@Marmiz thanks for the help
CamperBot
@camperbot
Sep 08 2017 04:22
breese8009 sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1038 | @marmiz |http://www.freecodecamp.com/marmiz
Claudio Restifo
@Marmiz
Sep 08 2017 04:28

@breese8009 Glad it worked but I think you overcomplicated.
You are inserting some elements into the page, and then want to listen to a click on that element created, right?

you could have simply add a listener to each specific element when rendered :)
example:

const render => () => {
let item = `<a onclick="customMethod">Test</a>`
whatever.prepend(item);
}

const customMethod = () => this.data('id')

@Manish-Giri More Regex help!! XD.

I am not sure why this matches the last test. It passes all the others. I thought the syntax {num1, num2} matched a range? Is it a bug? Here is my regex:

let ohStr = "Ohhh no";
let ohRegex = /h{3,6}/;
let result = ohRegex.test(ohStr);

\*Your regex should use curly brackets.
Your regex should not match "Ohh no"
Your regex should match "Ohhh no"
Your regex should match "Ohhhh no"
Your regex should match "Ohhhhh no"
Your regex should match "Ohhhhhh no"
Your regex should not match "Ohhhhhhh no"*/
Bryan Reese
@breese8009
Sep 08 2017 04:32
@Marmiz yea that is much cleaner
@Marmiz i got another question for ya
Manish Giri
@Manish-Giri
Sep 08 2017 04:32
@addisonday your regex only matches h 3 to 6 times
you need to put Oh{...} no in the / / bit
Ogundele Olumide
@Lumexralph
Sep 08 2017 04:33
@Manish-Giri :smiling_imp: :angry:
Manish Giri
@Manish-Giri
Sep 08 2017 04:33
@Lumexralph gggmmm
:bow:
Addison
@addisonday
Sep 08 2017 04:34
@Manish-Giri Why do you put three dots?
Ogundele Olumide
@Lumexralph
Sep 08 2017 04:34
@Manish-Giri did you check your slack?
Manish Giri
@Manish-Giri
Sep 08 2017 04:34
@addisonday that was just meant to indicate that your count goes in place of the ...
Bryan Reese
@breese8009
Sep 08 2017 04:34
sooo im creating this element below each time and i wanna remove the active class when another one is clicked, an give that the class active.... ive tried a few ways but, not gettin any luck
function renderListStyle(style) {
    let styleHtml=`
    <a href="#" class="list-group-item list-group-item-action" data-id="${style._id}">${style.type}</a>
    `

    $('.list-group-style').prepend(styleHtml);

}
Addison
@addisonday
Sep 08 2017 04:35
@Manish-Giri I see
Manish Giri
@Manish-Giri
Sep 08 2017 04:35
@Lumexralph I didn't get any notification after yesterday when I sent the message, let me check
Addison
@addisonday
Sep 08 2017 04:35
@Manish-Giri Thank you
CamperBot
@camperbot
Sep 08 2017 04:35
addisonday sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6513 | @manish-giri |http://www.freecodecamp.com/manish-giri
Bryan Reese
@breese8009
Sep 08 2017 04:36
i have the data-id console.logged each time i click on a diff element
function activeStyles(e) {
    e.preventDefault();
    let style = $(this).data('id');
    console.log(style);

}
Ogundele Olumide
@Lumexralph
Sep 08 2017 04:36
@Manish-Giri done with the board and added you as a member, checked your gmail? you should get a notification
Manish Giri
@Manish-Giri
Sep 08 2017 04:36
@Lumexralph yup, I checked, mine is the last message in there..
that I sent on 5th
Ogundele Olumide
@Lumexralph
Sep 08 2017 04:37
@Manish-Giri wow! let me check
Bryan Reese
@breese8009
Sep 08 2017 04:37
but i cant do with that id, what i thought i could
:(
Ogundele Olumide
@Lumexralph
Sep 08 2017 04:38
@Manish-Giri i wasn't notified by slack.... damn! that's true
@Manish-Giri were you able to peruse the board?
Manish Giri
@Manish-Giri
Sep 08 2017 04:40
@Lumexralph yep, It was helpful, because what I was doing was to list out every item as a new card in the same list, instead of using the back of a card for grouping multiple items related to the same task, which is what you did
I liked your way better, so i'm redoing the board to match this way
Claudio Restifo
@Marmiz
Sep 08 2017 04:43
@Manish-Giri :wave:
Ogundele Olumide
@Lumexralph
Sep 08 2017 04:43
@Manish-Giri awesome.... chilling then
Claudio Restifo
@Marmiz
Sep 08 2017 04:43
@Lumexralph :wave:
Ogundele Olumide
@Lumexralph
Sep 08 2017 04:44
@Marmiz Hey man!
Manish Giri
@Manish-Giri
Sep 08 2017 04:44
@Marmiz :wave: sensei
Ogundele Olumide
@Lumexralph
Sep 08 2017 04:44
good morning @Marmiz
Manish Giri
@Manish-Giri
Sep 08 2017 04:47
@Marmiz are you good with ruby?
JustCodeItBen
@JustCodeItBen
Sep 08 2017 04:50

https://beta.freecodecamp.com/en/challenges/regular-expressions/match-characters-that-occur-zero-or-more-times

In the challenge I linked there is the following regular expression that I don't understand:

Claudio Restifo
@Marmiz
Sep 08 2017 04:51
@breese8009 what I would do.
1: You listen for click on an element already, so at the end of that method call a second one to update the active class.
2: Pass to that method the newly selected id.
3: in that method hold a reference to the ID, remove the active from the old one and give it to the new one.
@Manish-Giri If by good you means I know it exists, then yes :)
I'm afraid I know nothing about Ruby
Bryan Reese
@breese8009
Sep 08 2017 04:53
heres my current code, but not workin
function activeStyles(e) {
    e.preventDefault();
    let style = $(this).data('id');
    let currentElem = $('.list-group-item[data-id='+style+']');
if(currentElem){
currentElem.addClass('active')
}else{
    currentElem.removeClass('active');
}
}
@Marmiz
Sandip Shrestha
@saninmersion
Sep 08 2017 04:55
@breese8009 you have a problem on your check. you are checking for currentElem and on the else statement basically you mean if there is no currentElem and you try to change it's property.
Bryan Reese
@breese8009
Sep 08 2017 04:56
@saninmersion so how would handle that so it removes the class when another currentElem gets a class 'active'
i donno why im not seein it and i swear ive encountered this problem before
Claudio Restifo
@Marmiz
Sep 08 2017 04:58
@breese8009 you pass the id.
If the id is different that current active id switch.
Otherwise move on
Bryan Reese
@breese8009
Sep 08 2017 04:59
so its always going to be true
Claudio Restifo
@Marmiz
Sep 08 2017 04:59
@Manish-Giri how good are you at unit testing redux sagas? :)
Bryan Reese
@breese8009
Sep 08 2017 04:59
so how could i write that?
hasClass?
in my conditional
like
ahhh
i donno
Markus Kiili
@Masd925
Sep 08 2017 05:06
Morning
Gersho
@Gersho
Sep 08 2017 05:07
:wave: @Masd925
Ogundele Olumide
@Lumexralph
Sep 08 2017 05:07
Morning Markus
Markus Kiili
@Masd925
Sep 08 2017 05:08
@Lumexralph Still working days and writing tests at night?
Bryan Reese
@breese8009
Sep 08 2017 05:09
AHHHHHH!!!!
Claudio Restifo
@Marmiz
Sep 08 2017 05:11
@breese8009 let's say you clicked on an element with id = 5 and the previous active id=3
const switchActive = (id) => {
  let active;
  if (active === id ) { // check if the id clicked is the same as the one we have
    alert('I'm already active')
  }
  //get prev active and remove
  document.getElementbyId(active).removeClass('active')
  // give it to the new id
  document.getElementById(id).addClass('active')
 // and don't forget to update active
 active = id
}
Ogundele Olumide
@Lumexralph
Sep 08 2017 05:12
@Masd925 :smile: actually implementing a twitter authentication to my app as another way a user could sign in, then I'm currently learning MongoDB..... i'll still write more tests
@Masd925 how's the inspiration for the java project?
Markus Kiili
@Masd925
Sep 08 2017 05:15
@Lumexralph Very good actually. Nice to have time to really look into subjects I am refreshing. Never really got grasp on how java inheritance goes under the hood. Class metaobjects etc.
Ogundele Olumide
@Lumexralph
Sep 08 2017 05:18
@Masd925 i trust you....... Detective Markus
Ogundele Olumide
@Lumexralph
Sep 08 2017 05:37
if you know you'll be dealing with this or arguments object in your work, silently bypass or avoid using arrow functions, talking from experience
Emmanuel Akodia
@akodiaemma
Sep 08 2017 06:14
@akodiaemma
guys i need help quickly understanding why my website displays nearly everything on responsive web tool on chrome and firefox but doesnt shows something different on mobile
can anyone help me understand that please
expo2017.ug is the website
Zhang LIn
@zl-cheetah
Sep 08 2017 06:27
image.png
Ken Haduch
@khaduch
Sep 08 2017 07:09
@ZhangLln - you want to use switch(val) and set the result in the answer variable, which you are returning to the caller,
And there should be no case val: line there
RakeshNerkar
@Rakesh18754
Sep 08 2017 07:34
are promises synchronous or asynchronus?
calvintor087
@calvintor087
Sep 08 2017 07:49
hey people :smile:
Zhang LIn
@zl-cheetah
Sep 08 2017 07:51
@khaduch thank you
CamperBot
@camperbot
Sep 08 2017 07:51
zl-cheetah sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3275 | @khaduch |http://www.freecodecamp.com/khaduch
calvintor087
@calvintor087
Sep 08 2017 07:54

I’m on the factorialize alogrithm of FCC. Just wondering why this solution works backwards from 5 -> 0 [i--] instead of from 0 -> 5 [i++].

Does it make a difference?

function factorialize(num) {
  for(i = num - 1; i >= 1; i--) {
    num *= i;
  }
  return num;
}

factorialize(5);
Morchid Chellali
@Morched23MJ
Sep 08 2017 07:57
You can inverse:
for(var i = 1; i <= num; i++)
It doesn't make a difference to the result, but in the second, you have to use condition: i < num, i must not reach num.
so: for(i = 2; i < num; i++), can do it. Better start from 2.
@calvintor087
Claudio Restifo
@Marmiz
Sep 08 2017 08:18
@Rakesh18754 async

even when resolving function synchronously the program finishes all the sync function before resolving promises.
example:

let asyncTask = () =>
  new Promise(resolve => {
    resolve();
  });

asyncTask().then(() => {
  console.log(1);
});

console.log(2);

Will still log 2 before 1

Markus Kiili
@Masd925
Sep 08 2017 08:51
@calvintor087 Looping backwards is a bit more efficient, because the condition is simpler (less variables to evaluate). In my opinion, looping forwards is easier to understand and usually better.
calvintor087
@calvintor087
Sep 08 2017 08:57
@Morched23MJ + @Masd925 thank you both :+1:
CamperBot
@camperbot
Sep 08 2017 08:57
calvintor087 sends brownie points to @morched23mj and @masd925 :sparkles: :thumbsup: :sparkles:
:cookie: 301 | @morched23mj |http://www.freecodecamp.com/morched23mj
:star2: 4477 | @masd925 |http://www.freecodecamp.com/masd925
Tiago Correia
@tiagocorreiaalmeida
Sep 08 2017 09:10
can you guys point some good apis to "play" with ?
Stephen James
@sjames1958gm
Sep 08 2017 10:14
@tiagocorreiaalmeida https://swapi.co/ - the star wars API
Abhinav Mishra
@abhinav-m
Sep 08 2017 10:54
heroiczero
@heroiczero
Sep 08 2017 10:57
@abhinav-thinktank it looks good to me. :+1: nice job
Abhinav Mishra
@abhinav-m
Sep 08 2017 10:57
@heroiczero thanks! :D
CamperBot
@camperbot
Sep 08 2017 10:57
abhinav-thinktank sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1702 | @heroiczero |http://www.freecodecamp.com/heroiczero
Markus Kiili
@Masd925
Sep 08 2017 10:59
@abhinav-thinktank Does the page need to be responsive?
Abhinav Mishra
@abhinav-m
Sep 08 2017 11:02
i dont think it does @Masd925
i tried making it so when it initially renders, it is adjusted according to the window size
Sean
@seanreeise
Sep 08 2017 11:10
@coymeetsworld I did, Mine is pretty much done just need to put it on code pen. Thanks for the help again.
CamperBot
@camperbot
Sep 08 2017 11:10
seanreeise sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 3001 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Ken Haduch
@khaduch
Sep 08 2017 11:27
@abhinav-thinktank - the graph page looks nice, but it does have problems with the legend overlapping the labels for the axes on smaller screens (shorter height) and the legend getting clipped on narrower screens. But I don't know if you have an easy way to fix that? And I just opened it on my phone and see that it clips the top off the title of the page. But since i cannot open it in debug mode, I don't know how much of that could be caused by the CodePen API?
Abhinav Mishra
@abhinav-m
Sep 08 2017 11:29
@khaduch yes, im aware of those things . Im also not sure how im gonna fix that, it's caused by font sizes and margins not being adjusted according to page size
@khaduch thank you for letting me know!
CamperBot
@camperbot
Sep 08 2017 11:29
abhinav-thinktank sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3276 | @khaduch |http://www.freecodecamp.com/khaduch
Abhinav Mishra
@abhinav-m
Sep 08 2017 11:29
@khaduch ill work on the responsive version soon when i get time!
basically the x position of the legend and overlapping stuff is hard coded, i need to place them according to window size too. Ill work on something to do that
Ken Haduch
@khaduch
Sep 08 2017 11:32
@abhinav-thinktank - that's great! Looks good so far- good luck on the project!
Abhinav Mishra
@abhinav-m
Sep 08 2017 11:34
@khaduch ty!
CamperBot
@camperbot
Sep 08 2017 11:34
abhinav-thinktank sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
api offline
Blauelf
@Blauelf
Sep 08 2017 12:00

@camperbot Is it you or something on the freeCodeCamp side that needs fixing? :wrench:

I really want my :cookie: s back.

mstellaluna
@mstellaluna
Sep 08 2017 12:02
@Blauelf camerbot has been fixed you should be getting cookies now
Blauelf
@Blauelf
Sep 08 2017 12:03
about @mstellaluna
CamperBot
@camperbot
Sep 08 2017 12:03
:cookie: 770 | @mstellaluna |http://www.freecodecamp.com/mstellaluna
mstellaluna
@mstellaluna
Sep 08 2017 12:03
@Blauelf thanks
CamperBot
@camperbot
Sep 08 2017 12:03
mstellaluna sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4591 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Sep 08 2017 12:05
@mstellaluna What happened to @camperbot? And can this happen again?
mstellaluna
@mstellaluna
Sep 08 2017 12:05
@Blauelf I didn't work on camperbot so I'm guessing this happened when the database crashed for FCC the other day and he just needed to be re-initialized
Blauelf
@Blauelf
Sep 08 2017 12:06
So you basically told it to "reboot"?
mstellaluna
@mstellaluna
Sep 08 2017 12:07
i don't know i just opened an Issue on GitHub for him.. someone fixed him
so i can't say what was done to fix him as it wasn't me :)
Blauelf
@Blauelf
Sep 08 2017 12:12
Berkeley responded to issue freeCodeCamp/freeCodeCamp#15857, so maybe he somehow fixed it.
mstellaluna
@mstellaluna
Sep 08 2017 12:13
yes 1 of 2 people who have access to FCC servers so he must have fixed it ... if an issue happens with camperbot , just open a GitHub issue and he'll fix it
Blauelf
@Blauelf
Sep 08 2017 12:17
The channel has been really quiet lately even with @camperbot working as expected. Is this a side-effect of the new semester having begun in some countries?
Anyway, thanks @mstellaluna for opening that github issue :)
CamperBot
@camperbot
Sep 08 2017 12:17
blauelf sends brownie points to @mstellaluna :sparkles: :thumbsup: :sparkles:
:cookie: 771 | @mstellaluna |http://www.freecodecamp.com/mstellaluna
Ghous Aly Shah
@ghousshah
Sep 08 2017 12:20
anyone know about aprse server function
plz help me
Blauelf
@Blauelf
Sep 08 2017 12:28
"parse server" like in https://github.com/parse-community/parse-server ? Never heard of. If it's server-side, maybe ask in freeCodeCamp/HelpBackend.
Ghous Aly Shah
@ghousshah
Sep 08 2017 12:39

I wish to create a parse cloud server function that estimate weight clothes from database type

You will add an object that Name ClotheType

ClotheType

string : type
int:basePrice

This function must naming : getClotheEstimation(type, weight) ==> price

This function must read the type into database and
return weight multiplcate by the type weight of clothes.

  • You must create a simple script that save ClotheType list object
Type basePrice

Pantalon 10
Veste 10
Costume 10
Pull 10
Gillet 10
Polo / T-Shirt Court 5
Polo / T-Shirt Long 5
Short 7
Jupe 10
Robe 10
Chemisier / Chemise 10
Accessoires 2
Cravate 2
Nœud Papillon 10
Foulard / Echarpe 10
Chaussure de ville 20
Basket 20
Sous-Corps 10
Lingerie 10

Blauelf
@Blauelf
Sep 08 2017 12:48
StackOverflow didn't like your do-my-homework post. Where did you get this piece of homework, maybe you could find information there?
Angelo
@TheCodingMeatball
Sep 08 2017 12:50
can anyone help me with my code? i made a questionnaire using javascript but it dont work.. dm please
Ghous Aly Shah
@ghousshah
Sep 08 2017 12:55
@Blauelf do you know about parse server
Blauelf
@Blauelf
Sep 08 2017 12:59
Already said, I've never heard of before. Also, I did not know there's a singular form of "clothes". I don't think they mean the verb "clothe".
sabahatullah
@sabahatullah
Sep 08 2017 13:00
could someone please help me with this. is that right?
document.body.addEventListener("click", function(event) {
if(event.target.id("choosePriceLocation")){
console.log('continue1 click');
}
}, false);
Blauelf
@Blauelf
Sep 08 2017 13:00
@sabahatullah I don't think that event.target.id is a function, but probably a string.
sabahatullah
@sabahatullah
Sep 08 2017 13:01
basically this id is not part of DOM on doc ready. it generates on user interaction. I wanna do some action whenever it appears and clicked
@Blauelf any idea?
Blauelf
@Blauelf
Sep 08 2017 13:04
if (event.target.id === "choosePriceLocation") looks like it could work for this.
sabahatullah
@sabahatullah
Sep 08 2017 13:04
oh yeah that was mistake however i tried this as well. doesn't seem to work
document.body.addEventListener("mousedown", function(event) {
if(event.target.id == "choosePriceLocation_LookForTicketsButton"){
alert('continue1 click');
}
}, false);
@Blauelf
also with the click.. on luck
no*
Blauelf
@Blauelf
Sep 08 2017 13:09
Are you sure you click an element with exactly this ID?
I just created a very minimal test case, and it worked, event bubbled up to the body and the listener got triggered. Also, other listeners on the way might stop the bubbling, even if the ID was right.
sabahatullah
@sabahatullah
Sep 08 2017 13:12
@Blauelf you know what you are a saviour, that was such a silly mistake by me. I was clicking on the wrong element Thanks for pointing that out.
CamperBot
@camperbot
Sep 08 2017 13:12
sabahatullah sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4592 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Sep 08 2017 13:13
Yeah, some bugs sit approximately 60-80cm in front of the monitor... :bug: :beetle:
sabahatullah
@sabahatullah
Sep 08 2017 13:13
lol thanks man
quick question here for for targeting class would that work
event.target.class == "edpcontent__ticketpriceinfo .cButton--primary"
Blauelf
@Blauelf
Sep 08 2017 13:16
It's .className, not .class. And using .className is a somewhat fragile approach, as it might break as soon as you add an additional class.
.classList is another option, depending on what you want to achieve.
sabahatullah
@sabahatullah
Sep 08 2017 13:19

what you suggest best for target these 2 scenarios
event.target.class == "edpcontentticketpriceinfo .cButton--primary" (parent class > actual class)
event.target.class == "button.cButton--cta.basketrecap
buy" (tagname.actualclasses)

with classList I read that there is compatibility issue

Blauelf
@Blauelf
Sep 08 2017 13:20
@sabahatullah Use inline code like `code containing _underscores_`=>code containing _underscores_ or code blocks, or escape the underscores, like \_.
Ah, so you want to match not a list of classes but a CSS selector?
There's Element.matches
sabahatullah
@sabahatullah
Sep 08 2017 13:23
yes I want to target particular elements which has those particular selectors
Blauelf
@Blauelf
Sep 08 2017 13:25
Then something like if (event.target.matches("edpcontent__ticketpriceinfo .cButton--primary"))?
I'm not sure how well-supported this feature is. Some people have really old browsers.
Blauelf
@Blauelf
Sep 08 2017 13:34
Also, some people have odd browsers. We frequently run into problems that seem to appear only on certain Apple devices (but not on others). And now go ask the customer which kind their iPad is (it's rectangular with round corners), and find an equivalent model for testing. And we currently not even use @media queries, where small differences in width might make a lot of a difference.
sabahatullah
@sabahatullah
Sep 08 2017 13:38
@Blauelf I tired this. no luck :(
document.body.addEventListener("click", function(event) {
    if(event.target.matches(".edpcontent__ticketpriceinfo .cButton--primary")){
        console.log("hello");

    }

}, false);
Bryan Reese
@breese8009
Sep 08 2017 13:39

so i have this rendered data

function renderStyles(style) {
    let styleHtml = `
    <!-- Style information -->

    <div class="card-header styleClass" data-styleid="${style._id}"><h1>${style.type}</h1>
        <div class="card-body-style">
            <p class="card-title style-desc">${style.description}</p>
            <p class="card-text style-comm">${style.comments}</p>
            <p class="card-text style-link"><a href="${style.link}">Wiki link</a></p>
            <div class="row">
                <div class="col-sm-2">
                    <button class="btn-danger delete-style" data-id="${style._id}">Delete</button>
                </div>
                <div class="col-sm-2">
                    <button class="btn-info edit-style" data-id="${style._id}">edit</button>
                    <button class="btn-info save-style save-edit" data-id="${style._id}">save</button>
                </div>
            </div>
        </div>
        <div>
        <button type="button" class="btn btn-primary add-school" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Add school</button>
        </div>
    </div>

    `

    $('.styleDisplay').prepend(styleHtml);
}

and I have this function that as of right now gives class active to some list elements that are on a diff part of the page, but now im trying to click the list element that has the same data-id as the rendered data element but it keeps giving me the same data-id over an over like it did was i was trying to get the list element data-id

function activeStyles(e) {
    e.preventDefault();
    let style = $(this).data('id');
    let currentElem = $('.list-group-item[data-id='+style+']');
$(this).parent().children().removeClass("active");
currentElem.addClass('active');
console.log($('.styleClass').data('styleid'));

}
Daniel Romero
@Ranacode
Sep 08 2017 13:40
I'm little confusing with the template engine 'pug' that was renamed to 'jade' and now if I'm not mistaken its renamed again to 'pug'?
What's the actual, pug or jade?
Blauelf
@Blauelf
Sep 08 2017 13:59
@sabahatullah But is the element you click a .cButton--primary below a .edpcontent__ticketpriceinfo?
@Ranacode It's pug, for trademark reasons. pugjs/pug#2184 (but old versions are still jade?)
Tiago Correia
@tiagocorreiaalmeida
Sep 08 2017 14:21
does anyone know a api that would return data that would be worth placing in a google maps api then usin makrdowns to place everyplace returned by the api'
Daniel Romero
@Ranacode
Sep 08 2017 14:28
yes
Well, you have the native geolocation api but it seems not enought for you
What data exactly do you want?
Random location data?
Specific places data=?
Tiago Correia
@tiagocorreiaalmeida
Sep 08 2017 14:31
one exemple
fuel places
all the the fuel places fro m a country
or all the supermarkets
something like that I think
Aizaz Shahid
@aizazshahid
Sep 08 2017 14:38
https://repl.it/Kq6X/latest/277296 , Is it appropriate way to do Exact Change challenge ?
Tiago Correia
@tiagocorreiaalmeida
Sep 08 2017 14:39
@moigithub have you used it?Was thinking about it support a country choose like I would pull all the data from my country and place it on maps with the info on their currect location
in the request filter for country
Marianissimus
@Marianissimus
Sep 08 2017 14:40
@forwebtech no way, there must be something shorter / easier
Aizaz Shahid
@aizazshahid
Sep 08 2017 14:40
@Marianissimus did you clear that one on your own?
Marianissimus
@Marianissimus
Sep 08 2017 14:41
yup. the for loop, including the if/else, must have been crazy to write...
Daniel Romero
@Ranacode
Sep 08 2017 14:41
Can I for example, when I create a model object, fill fields from another model object?
In mongoose
Tiago Correia
@tiagocorreiaalmeida
Sep 08 2017 14:42
nm might not be a great idea since I would have to request all the data and it would take alot of time to get it back
Daniel Romero
@Ranacode
Sep 08 2017 14:42
I'm reading the docs but I don't find something like that
Marianissimus
@Marianissimus
Sep 08 2017 14:42
@forwebtech in the Exact Change, the real challenge is, in my point of view, the floating error point
Aizaz Shahid
@aizazshahid
Sep 08 2017 14:43
@Marianissimus well for that i found a solution :
const format = number => parseFloat(number.toFixed(2));
Marianissimus
@Marianissimus
Sep 08 2017 14:43
@forwebtech yeah, but you must go forward and back, it's a mess
and what about the math itself, multiplications and stuff
a way to do it is: use cents. convert everything to cents, and don't use any decimal points.
Aizaz Shahid
@aizazshahid
Sep 08 2017 14:45
@Marianissimus yes everything will be in 100
Diego Mayer
@Chrono79
Sep 08 2017 14:45
@Marianissimus +1 to that, using cents
Aizaz Shahid
@aizazshahid
Sep 08 2017 14:47
@Marianissimus but then how array will return in float ?
like 0.01 will be 001 ? i think we can divide it, to get back
Diego Mayer
@Chrono79
Sep 08 2017 14:49
@forwebtech you divide by 100 at the end
Aizaz Shahid
@aizazshahid
Sep 08 2017 14:49
yeah !
Marianissimus
@Marianissimus
Sep 08 2017 14:55
yup. or hack it by converting it to a string and... you'll figure it out...
Aizaz Shahid
@aizazshahid
Sep 08 2017 14:59
well i will try to refactor it, actually the main problem is with the multiple if...else if statements if they will refactored then all the methods which created, will become unnecessary, so things will become more simple., But thanks for the cents one @Marianissimus
CamperBot
@camperbot
Sep 08 2017 14:59
forwebtech sends brownie points to @marianissimus :sparkles: :thumbsup: :sparkles:
:cookie: 445 | @marianissimus |http://www.freecodecamp.com/marianissimus
Aizaz Shahid
@aizazshahid
Sep 08 2017 15:03
but the happiness that comes after finishing some task on your own is really precious..
horo
@wolfHoro
Sep 08 2017 15:06
function mutation(arr) {
  // 请把你的代码写在这里
  var fstrings=arr[0].toLowerCase();
  var sstrings=arr[1].toLowerCase();
  if(fstrings.indexOf(sstrings)==-1){
     return true;
     }else{
     return false;
     }
}

mutation(["hello", "hey"]);
Why does the function mutation return false?
Jason Luboff
@JLuboff
Sep 08 2017 15:07
@wolfHoro You need to check every letter from the second string is inside the first string
horo
@wolfHoro
Sep 08 2017 15:08

@JLuboff

Function indexOf does not have this ability?

Jason Luboff
@JLuboff
Sep 08 2017 15:08
Use a loop to loop through each letter of the second string
Diego Mayer
@Chrono79
Sep 08 2017 15:10
@wolfHoro like that you're testing if second word is included in the first one
like come is included in welcome
horo
@wolfHoro
Sep 08 2017 15:11
Thank you. I'll try it
Diego Mayer
@Chrono79
Sep 08 2017 15:15
@JLuboff I've found a way to become rich easily, we just have to convince @Blauelf to solve one of these problems: http://www.claymath.org/millennium-problems
Jason Luboff
@JLuboff
Sep 08 2017 15:17
@Chrono79 There are some big words in there
But @Blauelf is a smart guy!
Markus Kiili
@Masd925
Sep 08 2017 15:17
@Chrono79 I can do the first easily. I did my thesis on Yang-Mills.
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 15:17
Sup ppl
Diego Mayer
@Chrono79
Sep 08 2017 15:18
@Masd925 go for it, it's open for all ;)
Markus Kiili
@Masd925
Sep 08 2017 15:18
@Chrono79 Until next monday. Is that ok?
Diego Mayer
@Chrono79
Sep 08 2017 15:19
Sure, no need to rush
Blauelf
@Blauelf
Sep 08 2017 15:19
Hasn't some guy recently claimed to have solved P=NP?
Jason Luboff
@JLuboff
Sep 08 2017 15:19
@Chrono79 If this is anything like his FCC projects... @Masd925 won't return with it until 9 months down the road :joy:
Markus Kiili
@Masd925
Sep 08 2017 15:20
@JLuboff Bart Simpson solved the ancient Chinece paradox of one hand clapping.
Jason Luboff
@JLuboff
Sep 08 2017 15:20
That is who I learned how to one hand clap from
Markus Kiili
@Masd925
Sep 08 2017 15:21
@JLuboff They apparently thought about if for 2000 years, but never tried.
Jason Luboff
@JLuboff
Sep 08 2017 15:21
...thats rather sad...its quite easy lol
Markus Kiili
@Masd925
Sep 08 2017 15:23
@Blauelf That would be interesting.
Blauelf
@Blauelf
Sep 08 2017 15:26
@Masd925 Some German professor who now withdrew his proof that P is not same as NP. https://cstheory.stackexchange.com/questions/38803/is-norbert-blums-2017-proof-that-p-ne-np-correct/
Bryan Reese
@breese8009
Sep 08 2017 15:29
ty @jenkynolasco11
dang
horo
@wolfHoro
Sep 08 2017 15:39
function mutation(arr) {
  var i;
  var j;
  var firstletter;
  var secondletter;
  var firststring=arr[0].toLowerCase();
  var secondstring=arr[1].toLowerCase();
  var firststringleg=firststring.length;
  var secondstringleg=firststring.length;
  for(i=0;i<secondstringleg;i++){
    firstletter=secondstring.charAt(i);
    for(j=0; j<firststringleg;j++){
      if(firstletter.indexOf(firststring.charAt(j))!==-1){
         continue;
         }else{
         return false;
         }
    }
  }

}

mutation(["hello", "hey"]);
How do I output true?
I really don't know how to solve this problem with GOOGLE
Jason Luboff
@JLuboff
Sep 08 2017 15:40
You have a lot of unneccessary variables there and you only need one loop
Change it up to use only one loop and only return true outside the loop
horo
@wolfHoro
Sep 08 2017 15:42
@JLuboff Thank you for reminding me. I'll try again
CamperBot
@camperbot
Sep 08 2017 15:42
wolfhoro sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2188 | @jluboff |http://www.freecodecamp.com/jluboff
Jenky W. Nolasco
@jenkynolasco11
Sep 08 2017 15:42
@breese8009 you owe me those xD
Marc
@MWBauer
Sep 08 2017 15:54
Morning everyone
For what's left of morning
Jason Luboff
@JLuboff
Sep 08 2017 15:55
I still have 3 hours of morning left
horo
@wolfHoro
Sep 08 2017 15:58
our time zone is very different. My present time is 0:02
Marc
@MWBauer
Sep 08 2017 15:58
Oh. Well, ok. I have 1.5 minutes
You must be out Cali way
Who has a thought on truncating?
Jason Luboff
@JLuboff
Sep 08 2017 15:59
Truncating what?
Marc
@MWBauer
Sep 08 2017 15:59
strings
Like; A-tisket a-tasket
I don't understand the middle 2 tests
Jason Luboff
@JLuboff
Sep 08 2017 16:00
Oh, you're refering to the challenge
There's three different test cases you need to account for
Marc
@MWBauer
Sep 08 2017 16:00

truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length) should return "A-tisket a-tasket A green and yellow basket".

truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2) should return "A-tisket a-tasket A green and yellow basket".

They give a string, and then the length of the test is the length of the string, and then the length + 2
function truncateString(str, num) {
  if (num >= 4) {
     var nStr = str.slice(0, num-3);
      return nStr += "...";
  } else if (num < 4) {
    var neStr = str.slice(0, num);
      return neStr += "...";
  }

}
This takes care of everything but the middle 2.
Jason Luboff
@JLuboff
Sep 08 2017 16:01
Yes, so the second parameter of the function is a number. If the number is greater than or equal to the length of your string, then you should not truncate
Marc
@MWBauer
Sep 08 2017 16:02
Is that a third if statement?
Jason Luboff
@JLuboff
Sep 08 2017 16:03
Yes, you need to account for three different cases, currently you only account for 2
Marc
@MWBauer
Sep 08 2017 16:03
if num >= str.length return str
I wasn't absolutely sure of the middle ones
Jason Luboff
@JLuboff
Sep 08 2017 16:03
Yes (its been a while since I've done the challenge) but that seems like it would work. That or after your if/else if statement just return str
Marc
@MWBauer
Sep 08 2017 16:05
I tried return str. It only returns a few characters.
I attempted str.slice(0). same 8 characters.
Jason Luboff
@JLuboff
Sep 08 2017 16:09
Show your code
Actually. I lied about being able to have it after your if/else if. Your first if condition would match, so instead, your first if condition should be if (num >= str.length){ return str; } else if...
Marc
@MWBauer
Sep 08 2017 16:11
I put return str; at the beginning and it works for that test. but then it won't go on
Gotcha. Thanks. That's what I needed.
thanks @JLuboff
CamperBot
@camperbot
Sep 08 2017 16:13
mwbauer sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2189 | @jluboff |http://www.freecodecamp.com/jluboff
Marc
@MWBauer
Sep 08 2017 16:14
Chunky Monkey is just asking us to take the 4 element array and break it into 2 2 element arrays within an array, right?
Jason Luboff
@JLuboff
Sep 08 2017 16:15
The array and the chunk size can vary
Daniel Romero
@Ranacode
Sep 08 2017 16:15
One random question.. How can I put data into html tag attributes with the pug engine rendering via express?
Jason Luboff
@JLuboff
Sep 08 2017 16:17

@Ranacode I'm not sure with pug, but with hbs (handlebars) you would send your object in your render

res.render('index.hbs', {href: 'http://google.com', imgSrc: 'http://myimg.com/img.jpg'});

then in the front end (again with hbs)

<a href="{{href}}"><img src="{{imgSrc}}"></a>
Daniel Romero
@Ranacode
Sep 08 2017 16:19
Yes, with handlebars, ejs.., its easy but in pug is weird
Jason Luboff
@JLuboff
Sep 08 2017 16:20
Well then dont use pug :D
Daniel Romero
@Ranacode
Sep 08 2017 16:21
Weee, I discover how to do it
Thanks by the way
I'm boring about using ejs and handlebars
Want to try something different
Blauelf
@Blauelf
Sep 08 2017 16:22
One of the projects I used had jade in their toolset (and Angular.js, CoffeeScript and a few others). I wonder whether they migrated to pug or something completely different. Why did those last three words remind me of Monty Python?
Daniel Romero
@Ranacode
Sep 08 2017 16:25
What last three words you refer, --> p u g ?
Marc
@MWBauer
Sep 08 2017 16:25
I'm thinking about a For loop with push.
"and now for something completely different"
Do I need to slice the original array? It's already and array
Blauelf
@Blauelf
Sep 08 2017 16:30
@MWBauer Exactly that one.
Marc
@MWBauer
Sep 08 2017 16:31
That was based on Monty
Blauelf
@Blauelf
Sep 08 2017 16:31
@MWBauer You can slice individual chunks to push.
Marc
@MWBauer
Sep 08 2017 16:31
I think that that's what I was thinking originally before I started reading
Blauelf
@Blauelf
Sep 08 2017 16:32
Slice can be abused to turn an array-like into an array, but its main use is copying a slice out of an array.
Marc
@MWBauer
Sep 08 2017 16:33
So I could run a for loop that slices then pushes into a new arr
Blauelf
@Blauelf
Sep 08 2017 16:33
Sure. Just make sure to adjust the indices from where to where you want the slice. They have to move with each iteration.
Marc
@MWBauer
Sep 08 2017 16:33
How would I make the arrays within an array?
Blauelf
@Blauelf
Sep 08 2017 16:34
Create an empty array above the loop and in the loop push slices to it.
Marc
@MWBauer
Sep 08 2017 16:34
I can push into an array, but is there a way within that for loop to make an array of a particular size?
Jason Luboff
@JLuboff
Sep 08 2017 16:34
@MWBauer You could push the value of your slice into your new array
Christopher McCormack
@cmccormack
Sep 08 2017 16:34
:wave:
Jason Luboff
@JLuboff
Sep 08 2017 16:34
slice returns an array
@cmccormack Yo
Marc
@MWBauer
Sep 08 2017 16:34
Ok. Hold on everyone
You're telling me what I know.
Yes, push creates an array. I save it to a new array.
Got it.
Jason Luboff
@JLuboff
Sep 08 2017 16:35
Push does not create an array, it adds to an existing array
Marc
@MWBauer
Sep 08 2017 16:35
But, how do I make the 2 arrays within an array? Is there a way to specify that within this for loop?
Christopher McCormack
@cmccormack
Sep 08 2017 16:35
.push([1,2,3])
Jason Luboff
@JLuboff
Sep 08 2017 16:35
If you push an array into an array, you're making a 2 dimensional array
Blauelf
@Blauelf
Sep 08 2017 16:36
@MWBauer Just figure out how many iterations you need and where your current slice should start and end.
It might be easier to use custom increments for the loop instead of the regular ++.
Marc
@MWBauer
Sep 08 2017 16:37
You're probably right

err....

function chunkArrayInGroups(arr, size) {
  var brArr = [];
  for (i = 0; i < 2; i++) {
    arr.slice.push(brArr);
  }
stupid c and v....right next to each other. BAH!
With this loop am I creating an array and pushing the first 2 iterations?
Blauelf
@Blauelf
Sep 08 2017 16:43
@MWBauer More like brArr.push(arr.slice(begin, end))
Christopher McCormack
@cmccormack
Sep 08 2017 16:43
you want to push onto brArr, not arr, and slice is a method that should be invoked first
Marc
@MWBauer
Sep 08 2017 16:43
dang it...ok
Christopher McCormack
@cmccormack
Sep 08 2017 16:43
Yeah what he said :)
Marc
@MWBauer
Sep 08 2017 16:44
it's working from the right to the left. It slices then pushes to brArr.
Blauelf
@Blauelf
Sep 08 2017 16:44

Also, declare i using var, otherwise it's implicitly global (worst bug in JavaScript design in my opinion).

And let your outer loop depend on arr.length and size, not just run twice.

Marc
@MWBauer
Sep 08 2017 16:45
var I = 0?
I thought with it being in the for loop it was very local
Christopher McCormack
@cmccormack
Sep 08 2017 16:46
nope
Blauelf
@Blauelf
Sep 08 2017 16:46
var creates the variable in the scope of the current function. Assigning to the variable without having it declared in any outer scope implicitly creates it as a global variable.
Christopher McCormack
@cmccormack
Sep 08 2017 16:47
If you haven't done loops with async functions yet, be aware of that now as it's important :)
Marc
@MWBauer
Sep 08 2017 16:49
My return is giving me 2 arrays. That's cool. But, they are identical
I goofed something.
Blauelf
@Blauelf
Sep 08 2017 16:50
@MWBauer Start and end index of your slice should move with the loop index.
Marc
@MWBauer
Sep 08 2017 16:50
thanks @cmccormack
CamperBot
@camperbot
Sep 08 2017 16:50
mwbauer sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1196 | @cmccormack |http://www.freecodecamp.com/cmccormack
Blauelf
@Blauelf
Sep 08 2017 16:58

@cmccormack You mean something like

for (var i = 1; i <= 10; i++) {
    setTimeout(function(){ console.log(i); }, 1000 * i);
}

?

Christopher McCormack
@cmccormack
Sep 08 2017 16:59
yup
Blauelf
@Blauelf
Sep 08 2017 16:59
In that one, you learn to love ES6's const and let and their block scopes. Less IIFEs.
Christopher McCormack
@cmccormack
Sep 08 2017 17:00
I made an example page to show people and that looks pretty close - https://codepen.io/cmccormack/pen/VWwQGm
Yeah I stopped using var altogether in most projects
Blauelf
@Blauelf
Sep 08 2017 17:03
I'm just not sure how efficient these are. With var, you open a new scope whenever you enter a function. With let, you might have a separate scope with each pair of curly braces (and a few more).
Christopher McCormack
@cmccormack
Sep 08 2017 17:04
var doesn't open a scope, not sure what you mean by that
Jason Luboff
@JLuboff
Sep 08 2017 17:05
So I'm making my game trading app... and I was thinking of limiting it to just Xbox One and PS4 games... Good or bad idea? I actually have PC included also, but thinking of removing it. PS3 and XBox 360 are pretty much dead at this point IMO
Blauelf
@Blauelf
Sep 08 2017 17:05
Functions create scopes. var always operates on current function's scope.
Christopher McCormack
@cmccormack
Sep 08 2017 17:05
@Blauelf and nested functions as well
oh I think I see what you're saying
@JLuboff is it hard to implement the other consoles? What about 3DS and Vita games?
Blauelf
@Blauelf
Sep 08 2017 17:08
Are console games actually tradable in these days, or are they bound to an account and will deactivate if offline for a week?
Christopher McCormack
@cmccormack
Sep 08 2017 17:09
Still tradeable, although same game makers will try to bind it by only allowing content once per key
I see that slowly going away over time though, sadly
Blauelf
@Blauelf
Sep 08 2017 17:11
Not a console gamer, was into PC gaming in the 90s, when PC game developers realised how easy it was to prevent copies if you could control the serial numbers by enforcing internet connection to the central server...
Jason Luboff
@JLuboff
Sep 08 2017 17:12
@cmccormack Not necessarily.. I just have to add a bit to my query and to my front end handling
@Blauelf Physical copies are still tradable, digital copies are not
And PC games I'm actual not sure
I think most are through Steam or something similar (so digital)
I think I will get rid of PC games.. just keep it to Consoles.
Christopher McCormack
@cmccormack
Sep 08 2017 17:13
PC games are pretty much locked these days not because of the developers as much as the distribution
Blauelf
@Blauelf
Sep 08 2017 17:13
My parents were on a 64k connection (DM0.20, maybe $0.15, per minute), so those games were out of my reach for multiple reasons.
Christopher McCormack
@cmccormack
Sep 08 2017 17:14
That's why I love to get games from GoG when I can
always DRM free, I can share with my Fiancee
@JLuboff probably for the best, but I would definitely include 3ds.
that's my console of choice lately as it's easy to pause between work or other things and it's portable
Just hard to find games that aren't too childish
Jason Luboff
@JLuboff
Sep 08 2017 17:15
Alright. I'll get rid of PC and add 3DS. Is PS Vita still a viable system? I haven't kept with the handhelds (last handheld I had was a PSP)
Christopher McCormack
@cmccormack
Sep 08 2017 17:15
no clue
Jason Luboff
@JLuboff
Sep 08 2017 17:16
Eh... maybe I'll just keep it to PS4 and XBone lol
Christopher McCormack
@cmccormack
Sep 08 2017 17:17
I guess it all depends on if you want people to actually use it or not :D
Could do stamps
Tai Jones
@taiJones00
Sep 08 2017 17:18
Vita isn't viable here in the US anymore. Although in Japan it's used like crazy and they still make games for it unlike here
Christopher McCormack
@cmccormack
Sep 08 2017 17:19
That would explain why I always see new games but never see vitas anywhere
I think I'm about finished with my D3 meteorite map - anyone care to take a look and critique? https://mackville.net/d3/globemap/
Blauelf
@Blauelf
Sep 08 2017 17:27
@cmccormack What's this kind of projection?
Christopher McCormack
@cmccormack
Sep 08 2017 17:27
thought it had a good 'fullness' to it
Blauelf
@Blauelf
Sep 08 2017 17:30
Found a meteorite with null for its mass :D (does that mean "didn't care as this thing just destroyed my car"?)
Christopher McCormack
@cmccormack
Sep 08 2017 17:30
Yeah I think that's exactly what the data says :)
I wasn't able to find anything that mapped the order of the country shapes in the json file to the actual country name, unfortunately
Jason Luboff
@JLuboff
Sep 08 2017 17:32
@cmccormack Just on first glance...I feel like there should be some padding to the bottom of the map
Adam Bohannon
@abohannon
Sep 08 2017 17:32
Can anyone explain why when I convert these integers to binary, it's not giving me 4 digits?
var hammingDistance = function(x, y) {
  const xBase2 = x.toString(2);
  const yBase2 = y.toString(2);

  console.log(xBase2); // output 1; expected 0001
  console.log(yBase2); // output 100; expected 0100
};

hammingDistance(1, 4);
Christopher McCormack
@cmccormack
Sep 08 2017 17:32
hmm I might have spoken too soon
Jason Luboff
@JLuboff
Sep 08 2017 17:33
@cmccormack And it took me a while to figure out where North America was :joy:
Christopher McCormack
@cmccormack
Sep 08 2017 17:33
@JLuboff padding?
Blauelf
@Blauelf
Sep 08 2017 17:33
@abohannon There's no padding. Try ("000"+x.toString(2)).slice(-4) if you are sure it's always 4 digits and never more.
Christopher McCormack
@cmccormack
Sep 08 2017 17:33
@JLuboff it wraps to the top
Jason Luboff
@JLuboff
Sep 08 2017 17:34
@cmccormack There's no empty space below the map, its just the footer, but it feels like it should have some scroll?
Blauelf
@Blauelf
Sep 08 2017 17:34
Oh... just realized... This is a usage for left-pad! https://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/
Christopher McCormack
@cmccormack
Sep 08 2017 17:34
@JLuboff ah you must have a smaller monitor than me
Adam Bohannon
@abohannon
Sep 08 2017 17:34
@Blauelf The challenge is asking to find the number of positions at which the corresponding bits are different, so i assume some integers could be longer when converted to bits?
Christopher McCormack
@cmccormack
Sep 08 2017 17:35
yeah I can look into that
Jason Luboff
@JLuboff
Sep 08 2017 17:36
@cmccormack
blob
My monitor is 1920 x 1200
Ah, but looking at it on my vertical screen (1200 x 1920) it has the padding
Christopher McCormack
@cmccormack
Sep 08 2017 17:37
Yeah I see the issue, I can try and push something to fix it
Jason Luboff
@JLuboff
Sep 08 2017 17:38
@cmccormack Dang...you've worked(work) for some high level companies.. ATT, HP, American express
Christopher McCormack
@cmccormack
Sep 08 2017 17:39
@JLuboff yeah but they were all for Amex
just moved consulting companies several times :D
They outsourced several years ago, then eventually determined it was a bad idea and now we're mostly insourced again
Fixed the bottom, can you check again real quick?
Jason Luboff
@JLuboff
Sep 08 2017 17:46
@cmccormack Ah gotcha. Still looks good lol
Ya it looks better now :+1:
Christopher McCormack
@cmccormack
Sep 08 2017 17:46
Thanks and thanks! @JLuboff
CamperBot
@camperbot
Sep 08 2017 17:46
:star2: 2190 | @jluboff |http://www.freecodecamp.com/jluboff
cmccormack sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
Jason Luboff
@JLuboff
Sep 08 2017 17:46
So is this D3 with React or just D3 (and also looks like bootstrap?)
Christopher McCormack
@cmccormack
Sep 08 2017 17:46
Anyone tried preact?
@JLuboff Yup all of them React for general layout, D3 for processing most of the data and displaying it
Jason Luboff
@JLuboff
Sep 08 2017 17:47
Gotcha
Christopher McCormack
@cmccormack
Sep 08 2017 17:48
My first few D3 projects were simple enough that I used mainly React for displaying everything and D3 just for processing some data, but the last two were more complex so I just let D3 handle all the SVG display stuff and React handle the rest
D3 is pretty cool though, I do recommend it
Jason Luboff
@JLuboff
Sep 08 2017 17:48
Ya D3 is on my list of things to learn
Christopher McCormack
@cmccormack
Sep 08 2017 17:49
It's pretty intense though when you start getting into the weeds. There is so much functionality
Super powerful though - most of the pan and zoom comes down to just these lines:
  const zoom_handler = zoom()
    .scaleExtent([1,16])
    .translateExtent([[0-100,0-100],[width+100,height+100]])
    .on( 'zoom', ()=>{ g.attr('transform', event.transform) })
Jason Luboff
@JLuboff
Sep 08 2017 17:50
Ya it looks super powerful and some of the examples of stuff it can produce is insane
Blauelf
@Blauelf
Sep 08 2017 17:51

@abohannon You could also do like

  while (xBase2.length < yBase2.length) {
    xBase2 = "0" + xBase2;
  }
  while (xBase2.length > yBase2.length) {
    yBase2 = "0" + yBase2;
  }

Do you know the ^ operator? It's highly inefficient as it turns JavaScript numbers (64-bit float) into 32-bit signed integers, computes a bit-wise XOR, and turns the result into a JavaScript number again. You could use this on x and y before turning it into binary, so with just one number to check, padding does not matter.

I just used a different way with a loop and maths, no strings involved, so also no padding :D

Christopher McCormack
@cmccormack
Sep 08 2017 17:51
@JLuboff I finished this one the other day - no idea how I could do it without D3 or something similar https://mackville.net/d3/forcedirected/
You have to read a lot of docs though, and many of the examples are for older versions. Fortunately the latest version simplifies a whole lot of the methods
Jason Luboff
@JLuboff
Sep 08 2017 17:52
Interesting. Not entirely sure what I'm looking at but its neat!
Adam Bohannon
@abohannon
Sep 08 2017 17:52
@Blauelf I'm not too familiar with bitwise operators as FCC doesn't really cover them. But it seems every coding challenge site I use deals with them, so even on the algos the sites claim are the simplest, I'm stumped =\
Christopher McCormack
@cmccormack
Sep 08 2017 17:52
@JLuboff which countries share physical borders, basically
with fun little bouncy effects :)
Jason Luboff
@JLuboff
Sep 08 2017 17:53
Ah
Blauelf
@Blauelf
Sep 08 2017 17:55
@abohannon Bitwise operators are highly inefficient in JavaScript, they make more sense in a language with actual integer types. They are most useful in areas with more direct contact to the computer, in reading binary files and so on.
Jason Luboff
@JLuboff
Sep 08 2017 17:58
I :heart: payday
Blauelf
@Blauelf
Sep 08 2017 17:59
@cmccormack Seems like we at Germany share borders with about anybody :D (have been to only 5 of those neighbouring countries so far)
Poor Yemen currently looks a bit stretched.
Christopher McCormack
@cmccormack
Sep 08 2017 18:02
@Blauelf it was weird seeing US with only a few, and weirder that one was Russian Federation
I've been to one of your neighbors (Austria) beautiful place
Blauelf
@Blauelf
Sep 08 2017 18:03
Wondered where USA and Russia shared a border. Alaska was Russian once.
Christopher McCormack
@cmccormack
Sep 08 2017 18:05
huh bering strait only separates the two by about 80km
Adam Bohannon
@abohannon
Sep 08 2017 18:12
@Blauelf is there a way to convert integers to bits of a standard length? I was able to solve a bunch of test cases for this algo, but there's one that returns two bits of different lengths so the result is incorrect. I saw this: (x >>> 0).toString(2) but that doesn't add zeros when passed 1 or 4.
Christopher McCormack
@cmccormack
Sep 08 2017 18:15
Couldn't you do something like '0'.repeat( standard length minus return bit length ) + return bits?
> var len = 8
> var bits = (6).toString(2)
> bits
'110'
> '0'.repeat(len - bits.length) + bits
'00000110'
I may be reading your question wrong though
Blauelf
@Blauelf
Sep 08 2017 18:19
@abohannon >>> 0 is sometimes used to restrict a number to be a 32-bit signed integer stored in a 64-bit float, as is | 0 or ~~. @cmccormack has some useful idea with '0'.repeat. I forgot about that, it came with ES6.
Christopher McCormack
@cmccormack
Sep 08 2017 18:21
Would this work pre-ES6?
> Array(len - bits.length).fill('0').join('') + bits
'00000110'
Blauelf
@Blauelf
Sep 08 2017 18:21
There's no fill before ES6.
Christopher McCormack
@cmccormack
Sep 08 2017 18:22
dangit
how did you initialize data then?
manually? gross
you can't use map without fill I don't think so maybe a for loop or something
Moisés Man
@moigithub
Sep 08 2017 18:24
'110'.padStart(8,0) es2017
Blauelf
@Blauelf
Sep 08 2017 18:25
I sometimes did stuff like new Array(len - bits.length + 1).join("0")
Christopher McCormack
@cmccormack
Sep 08 2017 18:25
@moigithub :thumbsup: neat thanks
CamperBot
@camperbot
Sep 08 2017 18:25
cmccormack sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3625 | @moigithub |http://www.freecodecamp.com/moigithub
Christopher McCormack
@cmccormack
Sep 08 2017 18:25
@Blauelf oh duh nice :)
Blauelf
@Blauelf
Sep 08 2017 18:26
@moigithub That's ES2017. Probably a reaction to leftpad :P
Jason Luboff
@JLuboff
Sep 08 2017 18:29
Huh... Codepen has been updated...and now my JS Calculator looks all messed up
Blauelf
@Blauelf
Sep 08 2017 18:32
They update all the time, mostly for having it display things like they think the user meant them.
Jason Luboff
@JLuboff
Sep 08 2017 18:32
Seems like its only that one. Wierd
Blauelf
@Blauelf
Sep 08 2017 18:33
Are you sure it's codepen and not one of your external libraries?
Jason Luboff
@JLuboff
Sep 08 2017 18:35
Oh wierd... its not my calculator :joy:
Christopher McCormack
@cmccormack
Sep 08 2017 18:35
when in doubt, blame @JLuboff
haha
Jason Luboff
@JLuboff
Sep 08 2017 18:36
Maybe I forked someone elses???
Christopher McCormack
@cmccormack
Sep 08 2017 18:36
probably
Blauelf
@Blauelf
Sep 08 2017 18:36
Maybe you tried to debug theirs
Jason Luboff
@JLuboff
Sep 08 2017 18:36
Ya... deleted now!
Man..I feel so overwhelmed by this Trading app. I can only work on it for a few minutes at a time
Christopher McCormack
@cmccormack
Sep 08 2017 18:41
keep running notes?
Jason Luboff
@JLuboff
Sep 08 2017 18:42
My only notes are my git commits :joy:
Christopher McCormack
@cmccormack
Sep 08 2017 18:42
nobody reads their own commit comments
Jason Luboff
@JLuboff
Sep 08 2017 18:44
Ya I know.
I think I do need to write out what I'm trying to accomplish though
Instead of working on this bit here than that bit
Christopher McCormack
@cmccormack
Sep 08 2017 18:46
Couldn't hurt
Jason Luboff
@JLuboff
Sep 08 2017 18:46
I mean...it could...but it shouldn't :D
Christopher McCormack
@cmccormack
Sep 08 2017 18:47
haha you may get a hangnail from all that commenting
Jason Luboff
@JLuboff
Sep 08 2017 18:48
:nail_care: ?
Christopher McCormack
@cmccormack
Sep 08 2017 18:48
haha perfect
Jason Luboff
@JLuboff
Sep 08 2017 18:50
Oh...great.. my Info is part of the breached equifax data
Christopher McCormack
@cmccormack
Sep 08 2017 18:53
how do you find out?
Just don't sign up for the protection since apparently that waves your right for any sort of class action lawsuit, etc
Christopher McCormack
@cmccormack
Sep 08 2017 18:56
uh who owns that domain? whois is a little vague and they want quite a bit of info
Jason Luboff
@JLuboff
Sep 08 2017 18:58
You should only give the last 6 of your social and your last name...but ya apparently the certificate is questionable at best (which is a problem obiviousily)
Christopher McCormack
@cmccormack
Sep 08 2017 18:58
last 6 is a lot of info though
Jason Luboff
@JLuboff
Sep 08 2017 18:59
True.
Christopher McCormack
@cmccormack
Sep 08 2017 19:00
I already dislike credit bureaus and their lack of transparency, and now they're leaking information and they'll probably charge us to do a check on our credit after their obligitory free checks end in a year or so
Jason Luboff
@JLuboff
Sep 08 2017 19:00
Ya, as I said, I didn't sign up for the protection, just checked to see if I was affectged
Blauelf
@Blauelf
Sep 08 2017 19:05
So the "social" is that number that you can use to open bank accounts all over the country within seconds, and the owner of the "social" gets the police visit later?
Jason Luboff
@JLuboff
Sep 08 2017 19:06
@Blauelf Your social security number is basically your unique identifier
It's used to track your credit
BrianWilliams28
@BrianWilliams28
Sep 08 2017 19:06
Can someone briefly explain what praseInt() function does?
Jason Luboff
@JLuboff
Sep 08 2017 19:06
and is assigned to you at birth
Or atleast early on in life
Blauelf
@Blauelf
Sep 08 2017 19:07
@BrianWilliams28 Interprets a string as an integer. Ignores extras like in "123CRAZYextrastuff"
Diego Mayer
@Chrono79
Sep 08 2017 19:07
@BrianWilliams28 it converts a string to an integer of a given radix
BrianWilliams28
@BrianWilliams28
Sep 08 2017 19:07
right so
if the string is all numbers like '01000001' for example
Diego Mayer
@Chrono79
Sep 08 2017 19:08
if radix is ommited it's a decimal one
BrianWilliams28
@BrianWilliams28
Sep 08 2017 19:08
how do you know what radix to give it?
Blauelf
@Blauelf
Sep 08 2017 19:09
@JLuboff We have something similar for taxes. When we had about the same in the German Democratic Republic, it was bad. Since we now live in the Federal Republic of Germany, it's good.
BrianWilliams28
@BrianWilliams28
Sep 08 2017 19:09
if you wanted to get the char code
Diego Mayer
@Chrono79
Sep 08 2017 19:09
parseInt('01000001') // 1000001
parseInt('01000001', 2) // 65
BrianWilliams28
@BrianWilliams28
Sep 08 2017 19:10
how does it go from 01000001 to 65 lol
what is the math behind what the 2 is doing?
Diego Mayer
@Chrono79
Sep 08 2017 19:10
if the string has only 1 and 0 I would suspect the radix you should use is 2 (that's a binary number)
Blauelf
@Blauelf
Sep 08 2017 19:11
@BrianWilliams28 027+126+025+024+023+022+021+120=64+1=650\cdot 2^7+1\cdot 2^6+0\cdot 2^5+0\cdot 2^4+0\cdot 2^3+0\cdot 2^2+0\cdot 2^1+1\cdot 2^0=64+1=65
BrianWilliams28
@BrianWilliams28
Sep 08 2017 19:11
is there a list somewhere that says what each radix does?
Blauelf
@Blauelf
Sep 08 2017 19:11
If it were decimal, there would be 10 instead of 2
BrianWilliams28
@BrianWilliams28
Sep 08 2017 19:13
it multiplies each number in the string by 2 to the power of how many numbers are in the string?
Blauelf
@Blauelf
Sep 08 2017 19:13
Other common radices are 8 (octal, used for example in UNIX file permissions) and 16 ("hexadecimal", a byte becomes two hexadecimal digits)
hexadecimal most common use seems to be css colors
red: #FF00000;
green: #00FF00;
blue: #0000FF;
black: #000000;
white: #FFFFFF;
Blauelf
@Blauelf
Sep 08 2017 19:14
Position in the string determines the power applied to the radix.
Just like decimal number 4711 is 4103+7102+1101+1100=4000+700+10+1=47114\cdot 10^3+7\cdot 10^2+1\cdot 10^1+1\cdot 10^0=4000+700+10+1=4711
Jason Luboff
@JLuboff
Sep 08 2017 19:17
@Blauelf Ya its also used for taxes, should have mentioned that. So the issue is, if it gets stolen along with your name, address, etc it is then easy for the theif to open credit cards under your name without you knowing unless you have credit monitoring (which cost money..)
Blauelf
@Blauelf
Sep 08 2017 19:17
Ternary can also be interesting. For example, the Cantor set consists of all the numbers between 0 and 1 that can be represented by ternary numbers consisting of digits 0 and 2 only (no 1).
1 in binary could be 0.2222222... with infinite digits, so is also included.
Adam Bohannon
@abohannon
Sep 08 2017 19:19
@Blauelf @cmccormack thank you for the help!
CamperBot
@camperbot
Sep 08 2017 19:19
abohannon sends brownie points to @blauelf and @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1197 | @cmccormack |http://www.freecodecamp.com/cmccormack
:star2: 4593 | @blauelf |http://www.freecodecamp.com/blauelf
Christopher McCormack
@cmccormack
Sep 08 2017 19:20
@BrianWilliams28 for example in base 10, each digit is 10 to some power, 0 is the rightmost:
125 = 5*10^0 + 2*10^1 + 1*10^2
Diego Mayer
@Chrono79
Sep 08 2017 19:25
Maybe not really a javascript problem, but I'm open to suggestions, any idea on how could I print the pool with the combination of colors chosen? When you try to print all goes south, let me know what you think: https://www.pelopincho.com/colorea-tu-pelopincho/
Blauelf
@Blauelf
Sep 08 2017 19:25
Also interesting are negative or fractal radices. Or balanced bases, like (-1), 0, 1 in ternary, then 8 would be 10(-1) for 132+0311301\cdot 3^2+0\cdot 3^1-1\cdot 3^0.
@Chrono79 South can also be nice direction, at least until you arrive in Antarctica.
Christopher McCormack
@cmccormack
Sep 08 2017 19:27
@Chrono79 maybe use svg image for pool so everything scales together?
Diego Mayer
@Chrono79
Sep 08 2017 19:27
@Blauelf who knows where the negative meaning of going south came
Christopher McCormack
@cmccormack
Sep 08 2017 19:28
Civil war soldiers in US?
piteto
@piteto
Sep 08 2017 19:29
south => down
north => up
Christopher McCormack
@cmccormack
Sep 08 2017 19:29
@piteto not on my map :D https://mackville.net/d3/globemap/
piteto
@piteto
Sep 08 2017 19:30
oh no lol
Adam Bohannon
@abohannon
Sep 08 2017 19:30
@Blauelf @cmccormack this is what I ended up with that passed all test cases:
var hammingDistance = function(x, y) {

  const len = Math.pow(31, 2);
  const xBase2 = x.toString(2);
  const yBase2 = y.toString(2);

 const xBits = '0'.repeat(len - xBase2.length) + xBase2;
 const yBits = '0'.repeat(len - yBase2.length) + yBase2;

  let counter = 0;

  for (let i = 0; i < xBits.length; i++){
    xBits[i] !== yBits[i] ? counter++ : ''
  }

  return counter;

};
suppose I could refactor some of that duplicate code into its own function
Christopher McCormack
@cmccormack
Sep 08 2017 19:31
@abohannon what was the goal?
Blauelf
@Blauelf
Sep 08 2017 19:31
@abohannon My solution was
function hammingDistance(a, b) {
    let dist = 0;
    while (a || b) {
        dist += (a % 2) ^ (b % 2);
        a = Math.trunc(a / 2);
        b = Math.trunc(b / 2);
    }
    return dist;
}
Adam Bohannon
@abohannon
Sep 08 2017 19:31
Find the number of positions at which the corresponding bits are different.
CamperBot
@camperbot
Sep 08 2017 19:31
find the number of positions at which the corresponding bits are different
nothing found
Christopher McCormack
@cmccormack
Sep 08 2017 19:31
find a soul CamperBot
CamperBot
@camperbot
Sep 08 2017 19:31
find a soul camperbot
nothing found
Adam Bohannon
@abohannon
Sep 08 2017 19:31
@Blauelf haha man so much better than mine.
Blauelf
@Blauelf
Sep 08 2017 19:32
@abohannon Have you seen the other solutions, like return (a^b).toString(2).match(/1/g).length;?
They should have used tests with numbers beyond the 32 bit integer, those would have failed on a^b
Adam Bohannon
@abohannon
Sep 08 2017 19:33
@Blauelf I've dabbled with ^ a bit, and I had a solution earlier that used a^b as the position to start comparing the bits, but it only passed about half the test cases
and i missed this crucial little detail: 0 ≤ x, y < 231.
Blauelf
@Blauelf
Sep 08 2017 19:34
Oh.
Adam Bohannon
@abohannon
Sep 08 2017 19:34
2^31
Blauelf
@Blauelf
Sep 08 2017 19:35
You are not on the same kata. In the link above, it's 1 <= a <= 2^20
juni
@junipberry
Sep 08 2017 19:35
guys, you know why this is not passing?
function or(expression1, expression2) {
  if (false && false) {
    return false;
  } else {
    return true;
  }
}
Adam Bohannon
@abohannon
Sep 08 2017 19:35
well actually i dunno how "crucial" it is, but I did have some bits that we long than the original length I was comparing, so I just decided to go for the max they would consider.
Blauelf
@Blauelf
Sep 08 2017 19:35
@junipberry false && false is always false
Jason Luboff
@JLuboff
Sep 08 2017 19:35
@junipberry If what is false and false?
Adam Bohannon
@abohannon
Sep 08 2017 19:35
@Blauelf I'm using leetcode
Blauelf
@Blauelf
Sep 08 2017 19:36
So one copied from the other.
Or both copied from a third one.
juni
@junipberry
Sep 08 2017 19:37
ah.
Blauelf
@Blauelf
Sep 08 2017 19:37
@junipberry Do you try to implement || without actually using ||?
juni
@junipberry
Sep 08 2017 19:37
ty @JLuboff
fixed
BrianWilliams28
@BrianWilliams28
Sep 08 2017 19:39
why doesn't this work? it's telling me that code.join() is not a function...
function binaryAgent(str) {
  let split = str.split(' ');
  for (let i = 0; i < split.length; i++) {
    let parse = parseInt(split[i], 2);
    let code = String.fromCharCode(parse);
    let join = code.join('');
    return join;
  }
}

binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 19:39
hey is chatbot's brownie jar officially over?
Christopher McCormack
@cmccormack
Sep 08 2017 19:39
@BrianWilliams28 code is a string not an array
Coy Sanders
@coymeetsworld
Sep 08 2017 19:39
@BrianWilliams28 join is an array function
Blauelf
@Blauelf
Sep 08 2017 19:40
@BrianWilliams28 Join and return after the loop. And create an empty array before that you push your characters to, or an empty string you append those to.
CamperBot
@camperbot
Sep 08 2017 19:40
roniquericketts sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1198 | @cmccormack |http://www.freecodecamp.com/cmccormack
juni
@junipberry
Sep 08 2017 19:41

can you also take a look at this pls

function countCharacter(str, char) {
  let reg = new RegExp (char, "gi");
  if (reg !== char) {
    return 0;
  } else {
  let ret = new RegExp (char, "gi");
    return str.match(ret).length;
  }
}

passing all but one test. Its not couting the number of times a character occurs.

*counting
Christopher McCormack
@cmccormack
Sep 08 2017 19:41
@RoniqueRicketts haha thanks? what was that for?
CamperBot
@camperbot
Sep 08 2017 19:41
cmccormack sends brownie points to @roniquericketts :sparkles: :thumbsup: :sparkles:
:cookie: 387 | @roniquericketts |http://www.freecodecamp.com/roniquericketts
Blauelf
@Blauelf
Sep 08 2017 19:42
@junipberry You mean if (!reg.test(char))?
BrianWilliams28
@BrianWilliams28
Sep 08 2017 19:42
@Blauelf thanks
CamperBot
@camperbot
Sep 08 2017 19:42
brianwilliams28 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4594 | @blauelf |http://www.freecodecamp.com/blauelf
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 19:42
@cmccormack testing the chatbot api becasue earlier someone say thanks and it didn't fire :)
CamperBot
@camperbot
Sep 08 2017 19:42
roniquericketts sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
api offline
Blauelf
@Blauelf
Sep 08 2017 19:43
Oh, API quota again :/
Christopher McCormack
@cmccormack
Sep 08 2017 19:43
@RoniqueRicketts looks like you broke it again
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 19:43
@cmccormack no I made it work everytime. :) plus you looked hungry
watch this.
@Blauelf thanks
CamperBot
@camperbot
Sep 08 2017 19:43
roniquericketts sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4595 | @blauelf |http://www.freecodecamp.com/blauelf
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 19:43
see
but if i say thanks again it breaks. @Blauelf
CamperBot
@camperbot
Sep 08 2017 19:44
roniquericketts sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
api offline
Blauelf
@Blauelf
Sep 08 2017 19:44
The problem is with the error message for "has given before recently", that error message seems to crash the function.
At least that's how I understand Berkeley's comment.
Jason Luboff
@JLuboff
Sep 08 2017 19:47
Stupid api
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 19:47
oh cool. I just sat here and watch the comments and learn but then I saw the pattern where its giving cookies but its not working for every users. Someone said ty or thanks it not working well
Christopher McCormack
@cmccormack
Sep 08 2017 19:47
Apparently there is noone with the skillset to fix a simple API
Maybe they need to tag @JLuboff in
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 19:49
@JLuboff fix it. @cmccormack Man I checked out some videos on how to make my apps host on heruko and now u both have me checking out this cool new knowledge I ended up even checking out electron Dang we can do so much with just html, css and js
Christopher McCormack
@cmccormack
Sep 08 2017 19:49
@RoniqueRicketts js is a programming language, so sure why not!
Jason Luboff
@JLuboff
Sep 08 2017 19:49
Psh... they don't pay me enough to fix their API ;)
Christopher McCormack
@cmccormack
Sep 08 2017 19:49
@JLuboff they pay you??
Jason Luboff
@JLuboff
Sep 08 2017 19:49
No, thats the problem :joy:
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 19:50
@JLuboff they pay you with friends and a good course outline to learn web development from
@cmccormack man. JS in my little head is a shiny toy that keeps getting shinyier** (my word) each time I check it out.
Christopher McCormack
@cmccormack
Sep 08 2017 19:52
@RoniqueRicketts There are so many fun tools to play with, that's for sure
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 19:54
@cmccormack yeah. The more I read up about what it can do the more it seems enticing. I randomly check out some of the out of the box apis from js and some of them amaze me.
Christopher McCormack
@cmccormack
Sep 08 2017 19:59
@RoniqueRicketts and just wait until you pull out all of your hair trying to implement some of the stuff in these libraries because their documentation is difficult haha
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 20:00
@cmccormack lol thanks for the heads up, Ill grow extra hair for those libraries :trollface:
CamperBot
@camperbot
Sep 08 2017 20:00
roniquericketts sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
api offline
Christopher McCormack
@cmccormack
Sep 08 2017 20:01
@RoniqueRicketts you'll need it! 75% pulling hair, 25% cheering you got it all working and then pretending it was easy
Anyone have an efficient clever solution for converting an array of objects to an object with properties from the original objects?
[ { a: 1, id: '1'}, ...] becomes { '1': { a: 1 }, ...}
Diego Mayer
@Chrono79
Sep 08 2017 20:06
@cmccormack write some example of the array
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 20:06
@cmccormack lol this is me working on the hair growth.
Christopher McCormack
@cmccormack
Sep 08 2017 20:06

haha was doing it. I did the blow but wonder if there's a nicer way:

  countryData.then((countrydata)=>{
    let countryObj ={}
    countrydata.forEach((c)=>{
      countryObj[+c['country-code']] = {'name': c.name, 'alpha2': c['alpha-2']}
    })
    return countryObj
  })

Cleaned up:

 countryData.then((countrydata)=>countrydata.reduce((obj,item)=>{obj[+item['country-code']]=item; return obj },{}))
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 20:06
hair.jpg
Christopher McCormack
@cmccormack
Sep 08 2017 20:07
@Chrono79 yes! That's perfect, thanks!
CamperBot
@camperbot
Sep 08 2017 20:07
cmccormack sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4532 | @chrono79 |http://www.freecodecamp.com/chrono79
Christopher McCormack
@cmccormack
Sep 08 2017 20:08
Forgot about reduce's initializer
@RoniqueRicketts yes that's also perfect haha
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 20:08
@cmccormack grab the sides for pulling and the back and just leave the top. :)
Daniel Romero
@Ranacode
Sep 08 2017 20:12
Hi
What's is the best way to sanitize inputs on mongoose model before saving?
In order to prevent inject html code
Christopher McCormack
@cmccormack
Sep 08 2017 20:14
Can you just convert it to a string?
Daniel Romero
@Ranacode
Sep 08 2017 20:15
Then with only defining the type on string is enough?
Christopher McCormack
@cmccormack
Sep 08 2017 20:16
I guess it depends on what you're trying to store and how it will be used.
Daniel Romero
@Ranacode
Sep 08 2017 20:20
Just a description on the user profile and comments
Christopher McCormack
@cmccormack
Sep 08 2017 20:20
You could convert the characters to ascii equivelents maybe, something like:
> '<div>'.replace(/[<>()!'*]/g,(c)=>`%${c.charCodeAt(0).toString(16)}`)
'%3cdiv%3e'
Daniel Romero
@Ranacode
Sep 08 2017 20:21
I was thinking about that, using regexp in the validator function
thanks @cmccormack
CamperBot
@camperbot
Sep 08 2017 20:21
ranacode sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1199 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Sep 08 2017 20:21
np
I used something very similar when doing the quote generator to build the URI for the Tweet
alpox
@alpox
Sep 08 2017 20:42
@cmccormack you can make your method a bit slicker with using reduce:
function(arr){
  return arr.reduce((cum, ob) => cum[ob.id] = ob, {});
}
Christopher McCormack
@cmccormack
Sep 08 2017 20:43
@alpox I posted a variation using reduce above, looks similar, but thanks!
CamperBot
@camperbot
Sep 08 2017 20:43
cmccormack sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1327 | @alpox |http://www.freecodecamp.com/alpox
alpox
@alpox
Sep 08 2017 20:48
@cmccormack ah didn't notice :D sry
Christopher McCormack
@cmccormack
Sep 08 2017 20:49
It's all good I still appreciate it :D
alpox
@alpox
Sep 08 2017 20:49
@cmccormack That one probably shouldn't be a one liner though :D is bit long for it
Christopher McCormack
@cmccormack
Sep 08 2017 20:49
it's not in my code, just on gitter
not sure why I thought it would look better here as one line... haha
alpox
@alpox
Sep 08 2017 20:50
@cmccormack :D
@cmccormack I use https://github.com/prettier/prettier for formatting my code - and don't worry anymore :D its awesome
Christopher McCormack
@cmccormack
Sep 08 2017 20:53
Did that guy do a blog post a while back on how difficult it was to create this? I remember reading something like that. Looks awesome though
piteto
@piteto
Sep 08 2017 20:54
Apparently that's what they use in codepen https://blog.codepen.io/2017/04/27/prettier-prettification/
I've been using it for my algos - copy/paste into codepen -> tidy js -> copy/paste into freecodecamp
Aizaz Shahid
@aizazshahid
Sep 08 2017 20:54
Have a look, now is it ok for exact change ? https://repl.it/Kq6X/latest/277296
piteto
@piteto
Sep 08 2017 20:55
A little too opinionated at times for my taste ;) but real quick way to tidy up code
Aizaz Shahid
@aizazshahid
Sep 08 2017 20:55
@cmccormack :wave:
Christopher McCormack
@cmccormack
Sep 08 2017 20:56
@forwebtech hi!
@piteto yeah I don't like the way it does ternary necessarily, I like the ? at the beginning of the line method
alpox
@alpox
Sep 08 2017 20:57
@piteto yea it used to get a bit messy with too many x => y => z => a => b => c => ...
:D
especially with type annotation through typescript
piteto
@piteto
Sep 08 2017 20:58
haha, I can imagine that would be a bit much :p
FlashHero
@FlashHero
Sep 08 2017 21:01
Can someone tell me what else should I have on my routes file other than routes and modules in nodejs and if I'm using the module in the routes file then do i need to include it in my main file or not
Jason Luboff
@JLuboff
Sep 08 2017 21:03
@FlashHero You only need to include the modules that are used in the file. So if its not used in your main file, you don't need it. But for instance, I use connect-flash so I need it in both my main file app.use('flash') (or whatever it is) and then in my route file where its used
FlashHero
@FlashHero
Sep 08 2017 21:06
@JLuboff Can you explain why would i need to require it in main file when I have it required in where its being used
Jason Luboff
@JLuboff
Sep 08 2017 21:07
@FlashHero ...you don't. Re-read what I wrote
FlashHero
@FlashHero
Sep 08 2017 21:07
I use connect-flash so I need it in both my main file app.use('flash') (or whatever it is) and then in my route file where its used I don't understand this
Jason Luboff
@JLuboff
Sep 08 2017 21:08
That was an example of where I need it in both files since both require some part of it
FlashHero
@FlashHero
Sep 08 2017 21:09
So, basically I require it where its being used
Jason Luboff
@JLuboff
Sep 08 2017 21:09
Yes
FlashHero
@FlashHero
Sep 08 2017 21:11
@JLuboff oh another question, where do you put your serialize and deserialize functions from passportjs on the routes file or main file
Jason Luboff
@JLuboff
Sep 08 2017 21:11
Main file
FlashHero
@FlashHero
Sep 08 2017 21:12
@JLuboff oh ok thanks for the help man
CamperBot
@camperbot
Sep 08 2017 21:12
flashhero sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2191 | @jluboff |http://www.freecodecamp.com/jluboff
Jason Luboff
@JLuboff
Sep 08 2017 21:12
:+1:
piteto
@piteto
Sep 08 2017 21:19
Hmmm, the smallest common multiple challenge took me 20 lines of code to answer. The next one is just arr.filter(func)[0]. Maybe I was overthinking smallest common multiples.
Is there a simpler way to accomplish this?
function smallestCommons(arr) {
  const min = Math.min(...arr), max = Math.max(...arr);
  let lcm = min;

  function getGcd(first, next) {
    let r = next % first;
    gcd = next = first;
    first = r;
    return r == 0 ? gcd : getGcd(first, next);
  }

  for (var i = min; i < max; i++) {
    getGcd(lcm, i + 1);
    lcm *= (i + 1) / gcd;
  }

  return lcm;  
}

smallestCommons([1,5]);
or do the algorithms jump around in difficulty?
Christopher McCormack
@cmccormack
Sep 08 2017 21:23
They jump around, sometimes it's more difficult simply because you don't consider the easier method, if it exists
piteto
@piteto
Sep 08 2017 21:24
Okay thanks @cmccormack
CamperBot
@camperbot
Sep 08 2017 21:24
piteto sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1200 | @cmccormack |http://www.freecodecamp.com/cmccormack
Diego Mayer
@Chrono79
Sep 08 2017 21:47
@piteto I haven't followed all your code but if the var name is lcm, why do you initialize it as min?
now that I did read the code it makes sense in the for loop
piteto
@piteto
Sep 08 2017 21:50
@Chrono79 That tells it where to start when getting the least common multiples for all the numbers in the range
Sorry, I should add code comments
Diego Mayer
@Chrono79
Sep 08 2017 21:51
yes, I've seen that, it's just that min is the only value that couldn't be lcm of 2 different numbers
but as it gets overwritten in the process, it's fine
piteto
@piteto
Sep 08 2017 21:57
getGcd() is the euclidean algorithm pseudocode from wikipedia and then I calculate the least common multiple in the for loop for each number in the range by dividing it by the greatest common divisor
Caleb David
@microworlds
Sep 08 2017 21:57
Hello guys, here's a little js array utility library. I need more contributors. I'm just learning the js language
https://github.com/microworlds/myArray
Jason Luboff
@JLuboff
Sep 08 2017 22:53
@Chrono79 You around still?
Diego Mayer
@Chrono79
Sep 08 2017 23:21
yes
Jason Luboff
@JLuboff
Sep 08 2017 23:22
Well you're too late! :D
I was going to ask a codewar question but I figured it out
Diego Mayer
@Chrono79
Sep 08 2017 23:22
:+1: