text:
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
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:
: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
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
Sep 08 2017 01:44
hey guys
Gersho
@Gersho
Sep 08 2017 01:44
Ronique Ricketts
@RoniqueRicketts
Sep 08 2017 01:45
Sup
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){

}
}
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=
${style.type}

$('.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 = Test whatever.prepend(item); } const customMethod = () => this.data('id') Addison @addisonday Sep 08 2017 04:30 @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= ${style.type} $('.list-group-style').prepend(styleHtml);

}
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
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 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.type}

${style.description}

${style.comments}

Wiki link

<button class="btn-danger delete-style" data-id="${style._id}">Delete</button>

 <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>

 <button type="button" class="btn btn-primary add-school" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Add school</button>

 $('.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:
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
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

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
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)

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 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? Jason Luboff @JLuboff Sep 08 2017 18:54 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 $0\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) Diego Mayer @Chrono79 Sep 08 2017 19:13 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 $4\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 $1\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 Blauelf @Blauelf Sep 08 2017 19:31 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 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: > '
'.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
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:


text:
## midi-osc

Tim has written and put together some code for a wireless USB midi/OSC connection.

comments in german, french and russian will be translated into english.
you can use LaTeX in your math comments, by using the $shortcode: [latex] E = m c^2$

format: plain


text:
Date & Time: Friday, March 01, 2013, 16:00-17:00.

Venue:Ramanujan Hall

Title:Grimm's Conjecture and smooth numbers

Speaker:Prof. Shanta Laishram

Abstract: Let $g(n)$ be the largest positive integer $k$ such that there are distinct primes $p_i$ for $1\leq i\leq k$ so that $p_i |n+i$. This function is related to a celebrated conjecture of C.A. Grimm which is considered very difficult. In this talk, we establish upper and lower bounds for $g(n)$ by relating its study to the distribution of smooth numbers. Standard conjectures concerning smooth numbers in short intervals imply $g(n) =O(n^\epsilon)$for any $\epsilon >0$. We also prove unconditionally that $g(n) =O(n^\alpha)$ with $0.45<\alpha <0.46$. The study of $g(n)$ has some interesting implications for gaps between consecutive primes. This is a joint work with R. Murty.


text:
# Plot system difference equations

Is this way correct to plot system of difference equation. For example

 StreamPlot[{(.2 (x^2) - x*y - .01 (y^2)), -.1 (y^2) + .9 x*
y + .02 (x^2)}, {x, -5, 5}, {y, -5, 5}, Axes -> True,

As far as I know, stream plot is for continuous time system (system of first order ode's) and not for difference equations (discrete system).

The system you posted is actually 2 ODE's and not difference equations. To show this, here is what you have

Clear["Global*"];
StreamPlot[{(2 (x^2) - x*y - 1/100 (y^2)), -1/10 (y^2) + 9/10 x*y + 2/100 (x^2)},
{x, -.1, 2}, {y, -.1, 3},
Axes -> True,
StreamPoints -> {{{{1, 2}, Red}, Automatic}}]

The red trajectory above, is specific solution which passes through initial conditions $$x(0)=1,y(0)=2$$. To show this, here are the two ODE's, solved using NDSolve with initial conditions $$x(0)=1,y(0)=2$$ and the phase plot is given using ParametricPlot, which gives the same exact red solution curve above.

ode1 = x'[t] == (2 (x[t]^2) - x[t]*y[t] - 1/100 (y[t]^2));
ode2 = y'[t] == -1/10 (y[t]^2) + 9/10 x[t]*y[t] + 2/100 (x[t]^2);
{solX, solY} = NDSolveValue[{ode1, ode2, x[0] == 1, y[0] == 2}, {x, y}, {t, -10, 10}]

ParametricPlot[{solX[t], solY[t]}, {t, -10, 10},
PlotStyle -> Red,  GridLines -> Automatic, GridLinesStyle -> LightGray]

Which gives the same solution from StreamPlot. This shows what you plotted is phase plot for 2 ODE's and not for difference equations.

It might be possible to do phase plot for difference equations ofcourse, but I do not think you can use StreamPlot for that. I do not know if Mathematica has special command for that, you might have to do it "manually". i.e. solve the two coupled difference equations, and do similar thing as ParametricPlot` but for the discrete solutions.


text:
# Tag Info

## New answers tagged prime-numbers

1

Since $p$ and $q$ are primes, the only factors you needs to rule out are those two numbers. Suppose $p$ divides $(p-1)(q-1)$. Then it divides either $p-1$ (clearly not true) or $q-1$. The latter means $q-1 = p \cdot x$, for some $x \ge 2$ (if $x = 1$ either $p$ or $q$ is even, which is only possible if the numbers are 2 and 3). However, then $q \ge 2p+1$, ...

5

The only reason you are seeing this is because you are dealing with such small primes. With primes like we would use in practice (1024 bits), the probability of this happening is very, very small. And, it can only happen when $e>\sqrt{\lambda(n)}$. Since we typically use $e=65537$ in practice, it is guaranteed to not happen. Anyways, there is no mistake ...

6

The table from the Handbook of Applied Cryptography is computed for candidate primes taken as odd integers. This is equivalent to using trial division by $2$ only. Note that section 4.48 specifies that: Using more advanced techniques, the upper bounds on $p_{k,t}$ given by Fact 4.48 have been improved. These upper bounds arise from complicated formulae ...

7

Update: the formula actually on page 165 in chapter 4 of the HAC is: $t=\lceil{1\over2}\cdot\lg n\rceil$, where $\lg$ is the base-2 logarithm; that is $t=\lceil{1\over2}\cdot k\rceil$; and that crude estimate asks for 512 Miller-Rabin tests for 1024-bit primes, not 5 or 6 tests as stated in the question based on the erroneous \$t=\lceil{1\over2}\cdot\lg ...

Top 50 recent answers are included


text:
# All

## Two-level System coupled to Phonons: Full Analytical Solution. (arXiv:1812.09043v1 [quant-ph])

We propose an analytical procedure to fully solve a two-level system coupled
to phonons. Instead of using the common formulation in terms of linear and
quadratic system-phonon couplings, we introduce different phonons depending on
the system electronic level. We use this approach to recover known results for
the linear-coupling limit in a simple way. More importantly, we derive results
for the quadratic coupling induced by a phonon frequency change, a problem
considered up to now as not analytically solvable.

## Ground state energy: Can it really be reached with quantum annealers?. (arXiv:1812.09251v1 [quant-ph])

Finding the ground state energy of a Hamiltonian $H$, which describes a
quantum system of several interacting subsystems, is crucial as well for
many-body physics as for various optimization problems. Variety of algorithms
and simulation procedures (either hardware or software based) rely on the
separability approximation, in which one seeks for the minimal expectation
value of $H$ among all product states. We demonstrate that already for systems
with nearest neighbor interactions this approximation is inaccurate, which

## Fiber coupled EPR-state generation using a single temporally multiplexed squeezed light source. (arXiv:1812.05358v2 [quant-ph] UPDATED)

A prerequisite for universal quantum computation and other large-scale
quantum information processors is the preparation of an enormously large number
of quantum states. For continuous variable approaches to quantum information
processing, squeezed states are the natural quantum resources, but most
demonstrations have been based on a limited number of squeezed state resources
due to the experimental complexity in up-scaling. The number of physical
resources can however be significantly reduced by employing the technique of

## Non-Hermitian extensions of higher-order topological phases and their biorthogonal bulk-boundary correspondence. (arXiv:1812.09060v1 [cond-mat.mes-hall])

Non-Hermitian Hamiltonians, which describe a wide range of dissipative
systems, and higher-order topological phases, which exhibit novel boundary
states on corners and hinges, comprise two areas of intense current research.
Here we investigate systems where these frontiers merge and formulate a
generalized biorthogonal bulk-boundary correspondence, which dictates the
appearance of boundary modes at parameter values that are, in general,
radically different from those that mark phase transitions in periodic systems.

## Semi-device-independent quantum money with coherent states. (arXiv:1812.09256v1 [quant-ph])

The no-cloning property of quantum mechanics allows unforgeability of quantum
banknotes and credit cards. Quantum credit card protocols involve a bank, a
client and a payment terminal, and their practical implementation typically
relies on encoding information on weak coherent states of light. Here, we
provide a security proof in this practical setting for semi-device-independent
quantum money with classical verification, involving an honest bank, a
dishonest client and a potentially untrusted terminal. Our analysis uses

## Evaluating Performance of Photon-Number-Resolving Detectors. (arXiv:1812.05422v2 [quant-ph] UPDATED)

We analyze the performance of photon-number-resolving (PNR) detectors and
introduce a figure of merit for the accuracy of such detectors. This figure of
merit is the (worst-case) probability that the photon-number-resolving detector
correctly predicts the input photon number. Simulations of various PNR
detectors based on multiplexed single-photon `click detectors' is performed. We
conclude that the required quantum efficiency is very high in order to achieve

## On quantum illumination, quantum reading, and the capacity of quantum computation. (arXiv:1812.08810v1 [quant-ph])

In this brief note, I clarify the crucial differences between three different
protocols of quantum channel discrimination, after some confusion has appeared
in recent literature.

## The quantum regression theorem for out-of-time-ordered correlation functions. (arXiv:1812.09065v1 [quant-ph])

We derive an extension of the quantum regression theorem to calculate
out-of-time-order correlation functions in Markovian open quantum systems.
While so far mostly being applied in the analysis of many-body physics, we
demonstrate that out-of-time-order correlation functions appear naturally in
optical detection schemes with interferometric delay lines, and we apply our
extended quantum regression theorem to calculate the non-trivial photon
counting fluctuations in split and recombined signals from a quantum light
source.

## On Testing Quantum Programs. (arXiv:1812.09261v1 [cs.SE])

A quantum computer (QC) can solve many computational problems more
efficiently than a classic one. The field of QCs is growing: companies (such as
DWave, IBM, Google, and Microsoft) are building QC offerings. We position that
software engineers should look into defining a set of software engineering
practices that apply to QC's software. To start this process, we give examples
of challenges associated with testing such software and sketch potential
solutions to some of these challenges.

## A General protocol for Distributed Quantum Gates. (arXiv:1812.07798v2 [quant-ph] UPDATED)

Distributed quantum computation requires to apply quantum remote gates on
separate nodes or subsystems of network. On the other hand, Toffoli gate is a
universal and well-known quantum gate. It is frequently used in synthesis of
quantum circuits. In this paper, a general protocol for implementing a remote
n-qubit controlled-U gate is presented with minimum required resources. Then,
the proposed method is applied for implementing a Toffoli gate in bipartite and


text:
# FORTRAN- How to read a non-uniformly formatted text file

• Fortran

## Main Question or Discussion Point

Hi all !!

I am a little new to FORTRAN and I am sorry if the title is confusing but I couldn't come up with anything better.

I have a file of which I am showing a snippet below:

Code:
*>>>>>>>>CHARMM22 All-Hydrogen Topology File for Proteins <<<<<<<
*>>>>>>>>>>>>>>>>>>>> and Nucleic Acids <<<<<<<<<<<<<<<<<<<<<<<<<
*>>>>> Includes phi, psi cross term map (CMAP) correction <<<<<<<
*>>>>>>>>>>>>>>>>>>>>>>   July, 2004    <<<<<<<<<<<<<<<<<<<<<<<<<<
* All comments to ADM jr. via the CHARMM web site: www.charmm.org
*               parameter set discussion forum
*
31  1

! references
!
!PROTEINS
!
!MacKerell, A.D., Jr,. Feig, M., Brooks, C.L., III, Extending the
!treatment of backbone energetics in protein force fields: limitations
!of gas-phase quantum mechanics in reproducing protein conformational
!distributions in molecular dynamics simulations, Journal of
!Computational Chemistry, 25: 1400-1415, 2004.
!
!MacKerell, Jr., A. D.; Bashford, D.; Bellott, M.; Dunbrack Jr., R.L.;
!Evanseck, J.D.; Field, M.J.; Fischer, S.; Gao, J.; Guo, H.; Ha, S.;
!Joseph-McCarthy, D.; Kuchnir, L.; Kuczera, K.; Lau, F.T.K.; Mattos,
!C.; Michnick, S.; Ngo, T.; Nguyen, D.T.; Prodhom, B.; Reiher, III,
!W.E.; Roux, B.; Schlenkrich, M.; Smith, J.C.; Stote, R.; Straub, J.;
!Watanabe, M.; Wiorkiewicz-Kuczera, J.; Yin, D.; Karplus, M.  All-atom
!empirical potential for molecular modeling and dynamics Studies of
!proteins.  Journal of Physical Chemistry B, 1998, 102, 3586-3616.
!
!IONS (see lipid and nucleic acid topology and parameter files for
!
!ZINC
!
!Roland H. Stote and Martin Karplus, Zinc Binding in Proteins and
!Solution: A Simple but Accurate Nonbonded Representation, PROTEINS:
!Structure, Function, and Genetics 23:12-31 (1995)
!
!NUCLEIC ACIDS
!
!Foloppe, N. and MacKerell, Jr., A.D. "All-Atom Empirical Force Field for
!Nucleic Acids: 2) Parameter Optimization Based on Small Molecule and
!Condensed Phase Macromolecular Target Data. 2000, 21: 86-104.
!
!and
!
!MacKerell, Jr., A.D. and Banavali, N. "All-Atom Empirical Force Field for
!Nucleic Acids: 2) Application to Molecular Dynamics Simulations of DNA
!and RNA in Solution. 2000, 21: 105-120.
!

MASS     1 H      1.00800 H ! polar H
MASS     2 HC     1.00800 H ! N-ter H
MASS     3 HA     1.00800 H ! nonpolar H
MASS     4 HT     1.00800 H ! TIPS3P WATER HYDROGEN
.
.
.
MASS    95 F3    18.99800 F ! Fluorine, trifluoro (see toppar_all22_prot_fluoro_alkanes.str)
MASS    99 DUM    0.00000 H ! dummy atom
!see NA section          --------------NOTICE THERE ARE COMMENTS B/W MASS RECORDS ALSO
!MASS   100 SOD  22.989770 NA ! Sodium Ion
!MASS   101 MG   24.305000 MG ! Magnesium Ion
!MASS   102 POT  39.102000 K  ! Potassium Ion! check masses
!MASS   103 CES 132.900000 CS ! Cesium Ion
!MASS   104 CAL  40.080000 CA ! Calcium Ion
!MASS   105 CLA  35.450000 CL ! Chloride Ion
!MASS   106 ZN   65.370000 ZN ! zinc (II) cation
!NA section
!MASS 101    HT    1.008000 H ! TIPS3P WATER HYDROGEN
From this file, I have to read the records starting with "MASS" (which end just before records starting with "DECL") and make a list out of it. I have to ignore all other lines. What is the best way to do this??

My approach:
Code:
        line_code='    '
do while(line_code .ne. 'DECL')
read(1000,*) line_code, temp_int1, temp_cname,temp_dbl1  !! ERROR IN THIS LINE, MOST PROBABLY
if(line_code .eq. 'MASS')then
atom_type_info(tot_atom_types)%type_code=temp_int1
atom_type_info(tot_atom_types)%type_cname=temp_cname
atom_type_info(tot_atom_types)%mass=temp_dbl1
tot_atom_types=tot_atom_types+1
endif

enddo
The problem is that in the read(1000,*) line, because of the comments in the file, a string is attempted to be read into an integer, which gives an i/o error.
I thought of another way, but its too much work. (first scan lines with read(1000,*) line_code and keep a line_counter. When you encounter MASS record, REWIND and read(1000,*)some_temp till line_counter-1. Then start reading the MASS record.) All this is because we cant REWIND one line before, we can only REWIND to the beginning of the file (right??)

Is there a better way? Like reading the whole line as a character array (with tabs and spaces), then reading from that array the first string. IF that is "MASS" go on and read from that line (stored as character array) rest of the values, otherwise ignore it. This is easy in C/C++ through getline and sscanf, but is there such a way in FORTRAN??

EDIT:
I found a way to read a line and not advance read pointer to next line through ADVANCE='NO' in READ statement, but now the problem is that when I read everything as a character, and there comes an integer in between, it gives an error.
Even if someone could tell me how to read a file in fortran line by line treating each line as a string (even if it is a number), that also might be a lot of help.

Last edited:

Related Programming and Computer Science News on Phys.org
Never Mind. Got it.
For someone else, you can read each line of text file as a string in fortran as follows:

do
read(1,'(a)',END=10) line !!END tells which statement to go to if all the lines have already been read
enddo

Also, from this line you read as a string, you can read formatted input. Just put the name of string in the place you put 'unit number' in read, as below:

Yes, the way to do it is to first read the line as a character string and, THEN, do what is called an internal read.

The one trick that allows this, though, is to read the line by specifying a format long enough to accommodate all you are trying to read out of it. Or, you can specify a very long format that always read the entire line.

Because in fortran spaces work as separators, you need to specify a format in order to read a string that is not enclosed in quotes and that should include spaces in itself. And, so, the most important line in the code that follows is:
Code:
read(*,'(A26)') line
The following code does the trick; you can test it by compiling and running from the command line using re-direction (mass < inputfile) :

Code:
program mass
character line*26
character code*4, temp_cname*4
integer temp_int1
real temp_dbl1

line(1:4) = '    '
do while (line(1:4) .ne. 'DECL')
if (line(1:4) .eq. "MASS") then
write(*,*) code, temp_int1, temp_cname, temp_dbl1 ! temporary line
! assign read values to pointer
endif
enddo
end
The code above declares the variable "line" to be just long enough to read up the last value you are interested in (the double)...you know as far as the number of characters to be read from the line (26); or, you could simply read the entire line every time by declaring "line" to be something like 130 characters long, instead...safer, just in case the format of your input file changes a bit.