These are chat archives for FreeCodeCamp/Help

3rd
Mar 2015
John Ellis
@johnmellis
Mar 03 2015 00:31
Hmm, anyone else have issues with Title Case a Sentence when using arrays to capitalize words?
function titleCase(str) {
  var arr_str = str.split(' ');
  var new_sentence = '';

  for(var i in arr_str){
    var word = arr_str[i];


    new_sentence += word.charAt(0).toUpperCase() + word.substr(1).toLowerCase()+ ' ';
  }

  return new_sentence;
}

titleCase("I'm a little tea pot");
There's my code
Cristián Berríos
@crisberrios
Mar 03 2015 00:33
for(var i in arr_str){
var word = arr_str[i];
when using for...in
and declaring i as the variable
you are passing the string to i
but not the index
so you're assigning arr_str['I'm'] to word
John Ellis
@johnmellis
Mar 03 2015 00:35
word[i] is still the string tho
it's just a unique index
Cristián Berríos
@crisberrios
Mar 03 2015 00:36
no
since the words are stored at arr_str[0], arr_str[1].... and so on
but calling arr_str["I'm"] will return undefined
John Ellis
@johnmellis
Mar 03 2015 00:37
It's the space at the end - try my code in the browser - it works
Cristián Berríos
@crisberrios
Mar 03 2015 00:37
hmm
I think you're right
I'm dumb today
John Ellis
@johnmellis
Mar 03 2015 00:37
tis' okay
Cristián Berríos
@crisberrios
Mar 03 2015 00:37
you are calling it on an array
so it's ok
just slept 3 hours last night :(
John Ellis
@johnmellis
Mar 03 2015 00:38
Yea, all good. I have to get that last space removed
haha I had one of those nights two nights ago
spent 4 hours building an angular app and built all of the angular promises like node promises
couldn't ifgure out why it didn't work
opened it in the morning - "ehhhhhhhh, wtf"
Cristián Berríos
@crisberrios
Mar 03 2015 00:39
why not pushing the capitalized words into an array
then joining them with a space?
or you can return a substring with 1 char removed from the tail
John Ellis
@johnmellis
Mar 03 2015 00:40
dunno - I probably should, I just threw an if(i < arr_str-1){ 'add a space'}
sometimes a good ole' if then just feels right
Cristián Berríos
@crisberrios
Mar 03 2015 00:40
hmm
that's not the cleanest way I can think of
John Ellis
@johnmellis
Mar 03 2015 00:40
is any of it?
lol
cerissa
@cerissa
Mar 03 2015 01:48
anyone wanna take a look and see whats wrong with this
var http = require('http'),
fs = require('fs');

function serveStaticFile(res, path, contentType,responseCode){
    if(!responseCode) responceCode = 200;
    fs.readFile(__dirname+ path, function(err, data){
        if(err){
            res.writeHead(500,{'Content-Type': 'text/plain'});
            res.end('500 - Internal Error');
        } else{
            res.writeHead(responseCode,
                { 'Content-Type': contentType});
            res.end(data);
        }
    });
}

http.createServer(function(req,res){
var path = req.url.replace( /\/?(?:\?.*)?$/,'').toLowerCase();
switch(path){
    case '':
    serveStaticFile(res, '/public/home.html', 'text/html');
    break;

    case '/about':
    serveStaticFile(res, '/public/about.html', 'text/html');
    break;
    case '/img/logo.jpg':
        serveStaticFile(res, '/public/img/logo.jpg', 
            'image/jpeg');
    break;
    default:
    serveStaticFile(res, '/public/home.html', 'text/html', 
        404);
 }
}).listen(3000);
console.log('Server started on localhost:3000; press ctr-c to terminate...');
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 01:51
@cerissa What's the error that you/re getting?
cerissa
@cerissa
Mar 03 2015 01:51
webpage not found
Danny Fritz
@dannyfritz
Mar 03 2015 01:52
where is that listen on the end coming from?
oh i see, from the http.createServer
cerissa
@cerissa
Mar 03 2015 01:52
i dont know it was on the example i was givien
Danny Fritz
@dannyfritz
Mar 03 2015 01:52
that is an interesting way to do routing
cerissa
@cerissa
Mar 03 2015 01:53
it was an example i was given
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 01:53
I can dig it.
Nathan
@terakilobyte
Mar 03 2015 01:53
you’ve spelled response wrong up top, your routing is uhmm, danny is on top of that
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 01:53
I used express btw
cerissa
@cerissa
Mar 03 2015 01:53
im about to move on to express,
the book was showing a few examples without express
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 01:54
Oh, ok.
Nathan
@terakilobyte
Mar 03 2015 01:54
move the console.log statement into the function argument of listen
you’ll see if you’re even spinning the server up
cerissa
@cerissa
Mar 03 2015 01:57
@terakilobyte thank you
Danny Fritz
@dannyfritz
Mar 03 2015 01:57
also, if you run it through a linter you can find many of these types of errors: http://i.imgur.com/NEZvcq5.png
cerissa
@cerissa
Mar 03 2015 01:58
@dannyfritz thanks
Nathan
@terakilobyte
Mar 03 2015 01:58

server.listen(port[, hostname][, backlog][, callback])#
Begin accepting connections on the specified port and hostname. If the hostname is omitted, the server will accept connections directed to any IPv4 address (INADDR_ANY).

To listen to a unix socket, supply a filename instead of port and hostname.

Backlog is the maximum length of the queue of pending connections. The actual length will be determined by your OS through sysctl settings such as tcp_max_syn_backlog and somaxconn on linux. The default value of this parameter is 511 (not 512).

This function is asynchronous. The last parameter callback will be added as a listener for the 'listening' event. See also net.Server.listen(port).

cerissa
@cerissa
Mar 03 2015 01:58
im hoping as i move onto express it will be better code
where would i put the use strict
cerissa
@cerissa
Mar 03 2015 02:05
at the very top?
Nathan
@terakilobyte
Mar 03 2015 02:07
yes
‘use strict’;
cerissa
@cerissa
Mar 03 2015 02:09
ok thanks just wanted to make sure i understood that correctly. i apperciate yall looking at my crazy not so good code
Ming Zhang
@Scripore
Mar 03 2015 02:26
function palindrome(str) {
  if (str.split('').reverse.join('') == str) {
    return true; 
  }
    return false;
}
what am I doing wrong here?
Nathan
@terakilobyte
Mar 03 2015 02:28
reverse is nothing, reverse() is a method
Ming Zhang
@Scripore
Mar 03 2015 02:29
ahhh, thanks!
Danny Fritz
@dannyfritz
Mar 03 2015 02:39
reverse isn't nothing! lol
it is a function. ;)
and functions don't have join defined on them usually
Nathan
@terakilobyte
Mar 03 2015 02:40
given the level of the bonfire I felt my explanation sufficient :P
I yield full correctness to @dannyfritz
John Ellis
@johnmellis
Mar 03 2015 03:28
@Scripore try this
```
if(str.toLowerCase().split('').reverse().join('').replace(/[^a-z0-9]/gi, '') == str.toLowerCase().split('').join('').replace(/[^a-z0-9]/gi,'')) then true else false
shit sorry for it not being code
You hae to make sure that you're moving it to lower case
and removing punctuation
then, the only difference between modified_string and string is the reversal
Ming Zhang
@Scripore
Mar 03 2015 04:02
thanks John. I tweaked it a bit and it works great.
return (str.toLowerCase().split('').reverse().join('').replace(/[^a-z0-9]/gi, '') == str.toLowerCase().replace(/[^a-z0-9]/gi,''));
I got confused by the ^ caret in the regex for a bit. I thought it indicated the start of the string.
Nathan
@terakilobyte
Mar 03 2015 04:28
@Scripore use === vs ==
if you need the type conversion, convert the type manually
Oliver
@Dadsaster
Mar 03 2015 04:29
@terakilobyte - I understand the difference between == and === but I don't know when == is ever appropriate
Ming Zhang
@Scripore
Mar 03 2015 04:31
gotcha, thanks!
Nathan
@terakilobyte
Mar 03 2015 04:37
I don’t think == is ever appropriate
be explicit in what you do
Danny Fritz
@dannyfritz
Mar 03 2015 04:39
@Scripore ^ does indicate the start of a string if it is used at the beginning of the regex. ^ inside and at the beginning of a [^] means everything but the characters in the []
Ming Zhang
@Scripore
Mar 03 2015 04:44
yeah, I had to evaluate the regex at regexr.com before it became clear to me.
John Ellis
@johnmellis
Mar 03 2015 04:53
@Scripore np - took me a while to get that one.
also /g means allow for repeats, and the i means it's case insensitive
@terakilobyte I've always used == instead of ===
Danny Fritz
@dannyfritz
Mar 03 2015 04:55
many linters don't allow == because of the crazy to figure out bugs it comes with.
John Ellis
@johnmellis
Mar 03 2015 04:56
It's probably the environment I'm in that causes me to do == instead of ===
I can't count the number of times that I've queried a clients salesforce account to write some data to SQL and they've used '#' instead of #
Danny Fritz
@dannyfritz
Mar 03 2015 04:57
SOQL statements?
are you writing APEX?
John Ellis
@johnmellis
Mar 03 2015 04:58
SQL*
Danny Fritz
@dannyfritz
Mar 03 2015 04:58
didn't know you could get access to direct SQL on salesforce
John Ellis
@johnmellis
Mar 03 2015 04:58
You can't
In larger accounts where you need to data mine - you have to stand up a web service to query the api
and data warehouse in SQL (if you need ACID compliance)
same w/ Netsuite and Workday
They are running on pretty beefy servers, but it's just too much to handle w/ all the bullshit goernance they put in the way
Nathan
@terakilobyte
Mar 03 2015 05:01
@johnmellis people do use ==, I just recommend against it
John Ellis
@johnmellis
Mar 03 2015 05:04
@dannyfritz I would agree if you're building a standalone app or a website where you're in complete control of inputs and their validations; when you're highly integrated with other systems that have some shit administrator you tend to use == more consistently than === because it provides you with a sudo control of the input.
pseudo*
hmmm, why isn't this working
function getMaxOfArray(numArray) {
  return Math.max.apply(null, numArray);
}


function largestOfFour(arr) {
  var maxnums = [];
  for(var i=0; i<arr.length; i++){
    maxnums.push(arr[i].getMaxOfArray());
  }    

  return maxnums;
}



largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Nathan
@terakilobyte
Mar 03 2015 05:07
use map
pass getMaxOfArray as it’s argument
John Ellis
@johnmellis
Mar 03 2015 05:08
Instead of the for loop, or within?
Nathan
@terakilobyte
Mar 03 2015 05:08
instead
if you’re iterating on a collection you should always think “How can I map, filter, or reduce this” (or a combination thereof) imo
but map here works nicely
you want a new array anyway
John Ellis
@johnmellis
Mar 03 2015 05:11
function getMaxOfArray(numArray) {
  return Math.max.apply(null, numArray);
}

function largestOfFour(arr) {
  var maxnums = [];
  for(var i=0; i<arr.length; i++){
    maxnums.push(arr[i].map(getMaxOfArray));
  }    
  return maxnums;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
That fails... am I missing something?
Nathan
@terakilobyte
Mar 03 2015 05:13
oh...
function getMaxOfArrayfunction largestOfFour(arr) {
  return arr.map(getMaxOfArray);
John Ellis
@johnmellis
Mar 03 2015 05:15
Sure as shit
I need to look through the MDN more often (and ask you)
Nathan
@terakilobyte
Mar 03 2015 05:16
map will invoke your callback with the elements of the subarray, which you’ve awesomely used apply so you can supply the arguments to max as an array
and that is the point of that challenge
map and apply
John Ellis
@johnmellis
Mar 03 2015 05:16
I've always done that in a loop
I've never used map before
Nathan
@terakilobyte
Mar 03 2015 05:17
loops are so… ugh
John Ellis
@johnmellis
Mar 03 2015 05:17
Yeah, but when you're self taught
Nathan
@terakilobyte
Mar 03 2015 05:17
I’m self taught :)
John Ellis
@johnmellis
Mar 03 2015 05:17
You literally start running in circles to fix problems ;)
Nathan
@terakilobyte
Mar 03 2015 05:17
started in december
John Ellis
@johnmellis
Mar 03 2015 05:17
What do you do for work?
Nathan
@terakilobyte
Mar 03 2015 05:17
day job is bomb squad
no joke
John Ellis
@johnmellis
Mar 03 2015 05:18
Well, that explains the efficiency
Nathan
@terakilobyte
Mar 03 2015 05:18
def get used to map, filter, reduce
John Ellis
@johnmellis
Mar 03 2015 05:18
and attention to detail
I will
Nathan
@terakilobyte
Mar 03 2015 05:18
^
they’ll lead you nicely into functional programming
Ming Zhang
@Scripore
Mar 03 2015 05:19
you've only started learning programming in December?
Nathan
@terakilobyte
Mar 03 2015 05:19
learning seriously for webdev, yeah
you can read my story on my blog
the post is titled running out of rocket fuel
Ming Zhang
@Scripore
Mar 03 2015 05:20
nice, I'll check it out. you're in the military right?
John Ellis
@johnmellis
Mar 03 2015 05:20
That's rad
Ming Zhang
@Scripore
Mar 03 2015 05:20
preparing to transition out into a web dev job?
Nathan
@terakilobyte
Mar 03 2015 05:22
yes military
yeah I want to work in software development when I get out
Julie Myers
@BlueOceanView
Mar 03 2015 05:23
@terakilobyte Which branch of the military are you in?
Nathan
@terakilobyte
Mar 03 2015 05:23
Army
Ming Zhang
@Scripore
Mar 03 2015 05:23
out of curiosity, how long have you been in?
Nathan
@terakilobyte
Mar 03 2015 05:24
The only boats I like have sails, and the air force has crappy colors
;)
oh, I’ve been in for…. 13 years now
John Ellis
@johnmellis
Mar 03 2015 05:25
Where are you stationed?
Nathan
@terakilobyte
Mar 03 2015 05:31
currently in Korea
Ming Zhang
@Scripore
Mar 03 2015 05:35
function compareNums(a,b) {
  return a - b;
}

function largestOfFour(arr) {
  var mainArray = [];
  for(i = 0; i < arr.length; i++) {
    arr[i] = arr[i].sort(compareNums);
    mainArray.push(arr[i][arr[i].length - 1]);    
  }
  return mainArray;
}
anything I should have done differently?
Julie Myers
@BlueOceanView
Mar 03 2015 05:35
Did they work?
Ming Zhang
@Scripore
Mar 03 2015 05:36
yup, just wondering if it should be refactored
John Ellis
@johnmellis
Mar 03 2015 05:36
need help on this one "Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a '...' ending."
function truncate(str, num) {
  // Clear out that junk in your trunk
  if(str.length > num){
    return str.substr(0,num)+'...';
  }else{
    return str;    
  }

}

truncate('A-tisket a-tasket A green and yellow basket', 11);
Ming Zhang
@Scripore
Mar 03 2015 05:37
I do have a question about the a - b expression in the compareNums function. what exactly is that operator called?
in Ruby it's referred to as the spaceship operator
John Ellis
@johnmellis
Mar 03 2015 05:38
Isn't it something like ==> in ruby
Julie Myers
@BlueOceanView
Mar 03 2015 05:38
@Scripore This is the way I solved it:
function getLargest(arr) {
  var newArray = [];
  var sorting = arr.sort(function(a, b){
    return a>b;
  });

  var getNum = sorting.pop();
  newArray.push(getNum);
  console.log(newArray);
}
getLargest([887, 9, 10001, 1000]); //[10001]
getLargest([9, 10, 68887, 2]); //[68887]
John Ellis
@johnmellis
Mar 03 2015 05:38
you can also use Math functions on the array
Nathan
@terakilobyte
Mar 03 2015 05:39
^
no need to sort, or manually iterate
Ming Zhang
@Scripore
Mar 03 2015 05:39
@johnmellis it's <=> in Ruby
John Ellis
@johnmellis
Mar 03 2015 05:40
function getMaxOfArray(arr){
  return Math.max.apply(null,arr)
}

function getLargest(arr){
  return arr.map(getMaxOfArray);
}
Nathan
@terakilobyte
Mar 03 2015 05:40
some dapper code there @johnmellis
now about your truncate
Ming Zhang
@Scripore
Mar 03 2015 05:40
@BlueOceanView Thanks, taking a look at it. one thing I really like about codewars is that you're able to see other people's solutions after completing the challenge.
John Ellis
@johnmellis
Mar 03 2015 05:41
that is some sexy code
Nathan
@terakilobyte
Mar 03 2015 05:42
so if the truncation is also supposed to leave room for 3 dots
John Ellis
@johnmellis
Mar 03 2015 05:42
go disarm a bomb
dmanit
damnit*
thanks
Nathan
@terakilobyte
Mar 03 2015 05:43
;)
John Ellis
@johnmellis
Mar 03 2015 05:43
also, for those of you on the text repeat
please, for the love of god just use
str.repeat(num);
Ming Zhang
@Scripore
Mar 03 2015 05:48
@BlueOceanView I think yours is a different challenge than the one I did. Mine was largestOfFour and had nested arrays.
Julie Myers
@BlueOceanView
Mar 03 2015 05:52
@Scripore Ahhh...that's right. I never did finish it up. Sorry. I got part of it to work though. :P
Nathan
@terakilobyte
Mar 03 2015 05:52
lol
John Ellis
@johnmellis
Mar 03 2015 06:04
I always get caught by the splice slice difference in arrays
John Ellis
@johnmellis
Mar 03 2015 06:11
function mutation(arr) {
 return (arr[0].indexOf(arr[1]) > -1) ? false : true;

}

mutation(['hello', 'hey']);
why does that fail?
Cristián Berríos
@crisberrios
Mar 03 2015 06:19
what do the instructions say?
John Ellis
@johnmellis
Mar 03 2015 06:24
Return true if the string in the first element of the array contains the string in the second element in any form.
Cristián Berríos
@crisberrios
Mar 03 2015 06:25
same question on main channel xD
it's checking if the letters from the 2nd array are present in the 1st
John Ellis
@johnmellis
Mar 03 2015 06:26
That's kinda misleading
Nathan
@terakilobyte
Mar 03 2015 06:31
misleading how?
I’m open to improving instructions
the exercises are about programming, not deciphering instructions (unless they are)
John Ellis
@johnmellis
Mar 03 2015 06:31
Well, it says the string in any form - it's not clear that you're looking for all letters contained within the first element.
Whe I read "string in the second element in any form" I think - regardless of case, not order of text.
Nathan
@terakilobyte
Mar 03 2015 06:32
all letters from teh second must be present in the first
so “the string in any form"
click on the more info button, I think I gave an example
Julie Myers
@BlueOceanView
Mar 03 2015 06:32
@terakilobyte Hmmm...I have to agree that the instructions could be a bit more clear.
John Ellis
@johnmellis
Mar 03 2015 06:33
The instructions say, "Return true if the string in the first element of the array contains the string in the second element in any form." I think the second string should be "letters"
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 06:33
coughregexcough
Nathan
@terakilobyte
Mar 03 2015 06:33
hmm
I’ll keep it noted and go through the analytics
John Ellis
@johnmellis
Mar 03 2015 06:33
It's no biggie
Nathan
@terakilobyte
Mar 03 2015 06:34
oh it is to me :)
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 06:34
It was pretty clear to me.
Nathan
@terakilobyte
Mar 03 2015 06:34
I wrote bonfire to replace coderbyte because I wanted challenges we maintained and curated
John Ellis
@johnmellis
Mar 03 2015 06:34
@piecedigital - you're too cool for school
Nathan
@terakilobyte
Mar 03 2015 06:34
they’re meant to be quality
each one has a purpose
John Ellis
@johnmellis
Mar 03 2015 06:34
it reminds me of the "how many ways can you make $1.25 using dimes, nickels, and quarters."
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 06:35
@johnmellis B)
Julie Myers
@BlueOceanView
Mar 03 2015 06:35
@terakilobyte Could you include each problems purpose in the instructions?
Nathan
@terakilobyte
Mar 03 2015 06:35
that would really blow it away
the idea is to make you research the mdn
but not point out “hey look at this method"
then you may ignore others
John Ellis
@johnmellis
Mar 03 2015 06:35
technically, my code should work
Nathan
@terakilobyte
Mar 03 2015 06:35
let’s see what you have
John Ellis
@johnmellis
Mar 03 2015 06:35
because there is no index of 'hey' in 'hello'
I linked it above
function mutation(arr) {
 return  Boolean(arr[0].search(arr[1]));

}

mutation(['hello', 'hey']);
mutation(['shit', 'fuck']);
Elliescode
@EllieAdam
Mar 03 2015 06:36
lol
John Ellis
@johnmellis
Mar 03 2015 06:36
the second mutation was added for flavor
Nathan
@terakilobyte
Mar 03 2015 06:36
I’d recommend looking at str.match
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 06:37
I'm regularly expressive.
John Ellis
@johnmellis
Mar 03 2015 06:37
Here's why it's confusing
Nathan
@terakilobyte
Mar 03 2015 06:37
well, search and match are equivalent
Ming Zhang
@Scripore
Mar 03 2015 06:37
return (arr[0].indexOf(arr[1]) > -1) ? false : true;
Nathan
@terakilobyte
Mar 03 2015 06:38
but let’s reason through it
Ming Zhang
@Scripore
Mar 03 2015 06:38
isn't the false and true in the wrong place?
Nathan
@terakilobyte
Mar 03 2015 06:38
and use expressive code
John Ellis
@johnmellis
Mar 03 2015 06:38
@terakilobyte here's my reasoning
Nathan
@terakilobyte
Mar 03 2015 06:38
not bullshit arr[0] arr[1] references
John Ellis
@johnmellis
Mar 03 2015 06:38
when you look at the MDN
but you're not asking for a direct match string to string
Nathan
@terakilobyte
Mar 03 2015 06:39
yeah I just read it, it says search is faster than match but equivalent
right, I know
however, you are missing the part “of any form"
consider ’abba’ === ‘baab' //should be true
John Ellis
@johnmellis
Mar 03 2015 06:40
Right, but doesn't search convert to regex in my boolean example?
order !== form
Nathan
@terakilobyte
Mar 03 2015 06:41
any form includes order
as long as all the letters from the second string are present in the first
the second string is then present, in any form
also consider
John Ellis
@johnmellis
Mar 03 2015 06:43
Alright, you're the author, you win
Nathan
@terakilobyte
Mar 03 2015 06:43
Boolean(-1) === true
I will fix up the description and add even more test cases
I do see how it can be misleading, especially with the tests I provided
John Ellis
@johnmellis
Mar 03 2015 06:44
I think if you rewrite a test or add another to show that the letters are scrambled
(even tho they aren't in the tests)
Nathan
@terakilobyte
Mar 03 2015 06:44
but also, your boolean logic fails
If successful, search() returns the index of the first match of the regular expression inside the string. Otherwise, it returns -1
as I said Boolean(-1) is in fact true
I’m betting if you just did a ternary like
return str1.search(str2) !== -1 ? true : false;
John Ellis
@johnmellis
Mar 03 2015 06:46
well, but why would two of the 3 tests match then?
ok, let me try
still fails the last test
function mutation(arr) {
 return  (arr[0].search(arr[1]) !== -1) ? true : false;
}
mutation(['hello', 'hey']);
Nathan
@terakilobyte
Mar 03 2015 06:48
it’s returning true?
John Ellis
@johnmellis
Mar 03 2015 06:48
the mutation listed passes
the other's do not
Harshal
@McQuinTrix
Mar 03 2015 06:48
Is there any sort() method like C++11 for javascrit ?
Nathan
@terakilobyte
Mar 03 2015 06:48
as they shouldn't
it’s neither converting the case nor reordering them, sorry, I was misunderstanding you
keep in mind you can abuse sort() on this and not pass an argument to it
John Ellis
@johnmellis
Mar 03 2015 06:50
function mutation(arr) {
 return  (arr[0].search(arr[1]) !== -1) ? true : false;
}

mutation(['hello', 'hey']); // returns false
mutation(['zyxwvutsrqponmlkjihgfedcba', 'qrstu']); // returns false
mutation(['hello', 'Hello']); //returns false
Nathan
@terakilobyte
Mar 03 2015 06:50
since sort() defaults to lexicographic string order
the 2nd and 3rd should return true
John Ellis
@johnmellis
Mar 03 2015 06:50
Sorry , sec
Harshal
@McQuinTrix
Mar 03 2015 06:50
2nd wont
it is iin reverse order
John Ellis
@johnmellis
Mar 03 2015 06:50
In that code, they all return false
Harshal
@McQuinTrix
Mar 03 2015 06:51
:[
Nathan
@terakilobyte
Mar 03 2015 06:51
yeah I know
Harshal
@McQuinTrix
Mar 03 2015 06:51
]:
sorry for angry sign
Nathan
@terakilobyte
Mar 03 2015 06:51
sorry I thought you were asking about that case alone
John Ellis
@johnmellis
Mar 03 2015 06:51
I'm more confused now than when I started lol
Nathan
@terakilobyte
Mar 03 2015 06:51
ok
Harshal
@McQuinTrix
Mar 03 2015 06:51
no intention for it
John Ellis
@johnmellis
Mar 03 2015 06:51
Is the idea to use search?
or regex?
Harshal
@McQuinTrix
Mar 03 2015 06:51
try regex :3
Nathan
@terakilobyte
Mar 03 2015 06:51
the challenge is to see if the second string is presetn in the first string, in any form
meaning forwards, backwards, jumbled, upside down, deep fried, pickled, or frozen
John Ellis
@johnmellis
Mar 03 2015 06:52
gotcha; less about the method and more about finding the issue
Harshal
@McQuinTrix
Mar 03 2015 06:52
if it is jumbled .. we can use sort () .. can we ?
John Ellis
@johnmellis
Mar 03 2015 06:52
I see what you're saying with sort
hmmm
Julie Myers
@BlueOceanView
Mar 03 2015 06:52
@terakilobyte Why not put: "any form
meaning forwards, backwards, jumbled, upside down, deep fried, pickled, or frozen" in your instructions?
John Ellis
@johnmellis
Mar 03 2015 06:53
I think having a less contrite example for the second test would make more sense
Nathan
@terakilobyte
Mar 03 2015 06:53
I’ll clean up the description, no worries :)
Harshal
@McQuinTrix
Mar 03 2015 06:53
for anagram i used sort :3
@terakilobyte .. you in FCC team :O
i am sorry i didn't know that
John Ellis
@johnmellis
Mar 03 2015 06:54
Ok, before you do that - why doesn't my .search() work?
Nathan
@terakilobyte
Mar 03 2015 06:55
because search is using an exact match
Harshal
@McQuinTrix
Mar 03 2015 06:55
yeah!>:
Nathan
@terakilobyte
Mar 03 2015 06:55
think of it like this when the string is converted, imagine the values [‘hello’, ‘hi’]
you are really doing ‘hello’.search(/hi/g)
now if we took [‘hello’, ‘Hello’] you could do ‘hello’.search(/hello/gi) and it would work
as you just told it to ignore case
John Ellis
@johnmellis
Mar 03 2015 06:57
Okay, bigger question
Nathan
@terakilobyte
Mar 03 2015 06:57
when it implicity makes the regex object for you it makes the most basic regex it can
John Ellis
@johnmellis
Mar 03 2015 06:57
Should we be doing these bonfires as if we know the inputs, or should we be doing them as if the inputs are unpredictable?
Harshal
@McQuinTrix
Mar 03 2015 06:57
also for ["hi","ahhahahihahahah"] it should work
better click the run to see testcases and then formulate answers ..
John Ellis
@johnmellis
Mar 03 2015 07:05
@piecedigital throw me the damn regex will ya? I don't quite understand why my shit's failing.
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 07:08
RegExp is what you have to use to make a new regex object from a variable
So something like this
var x = new RegExp("[" + arr[1] + "]", "i")
I think that's what I did.
Well, I use parenthesis instead of square brackets.
Square brackets will just match any of the letters
Harshal
@McQuinTrix
Mar 03 2015 07:10
wit reverse too/////???
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 07:11
Yeah, no matter the order square brackets will just match each character.
Parenthesis match the expression in the given order.
Harshal
@McQuinTrix
Mar 03 2015 07:12
awesome ... thank you for this info mann..
John Ellis
@johnmellis
Mar 03 2015 07:13
hmm, the ['hello','hey'] is still failing
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 07:13
As far as making sure all of the letters are in the string I'm not sure.
John Ellis
@johnmellis
Mar 03 2015 07:13
that's where I'm getting hung up
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 07:13
It's matching true, right?
John Ellis
@johnmellis
Mar 03 2015 07:13
yeah
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 07:14
that's cuz it's matching the 'h' and 'e'
John Ellis
@johnmellis
Mar 03 2015 07:14
Right but, assuming you don't know the value that's going to be passed in arr[1]
you can't write regex for it outside of ['hey']
or, 'hey'/gi
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 07:15
here's an idea: "abcde".match(/[ac]/g).length;
John Ellis
@johnmellis
Mar 03 2015 07:16
I think my brain's just fried
been at this for 6hrs now
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 07:16
hehe
John Ellis
@johnmellis
Mar 03 2015 07:16
(not this challenge, but coding)
see ya all later
Harshal
@McQuinTrix
Mar 03 2015 07:16
calm down dude .. try in console
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 07:16
It'll return an array.
Harshal
@McQuinTrix
Mar 03 2015 07:16
no no finish it
don't go
fiinsh what you started
John Ellis
@johnmellis
Mar 03 2015 07:16
I'm at the point where IDGAF
about this exercise
Harshal
@McQuinTrix
Mar 03 2015 07:17
hahahaha .. alright .. eat a ice cream
John Ellis
@johnmellis
Mar 03 2015 07:17
It's just breaing my brain right now; and I feel like I haven't learned what @terakilobyte is trying to teach - which is where I get frustrated
Cristián Berríos
@crisberrios
Mar 03 2015 07:18
think of scrabble. see if you can get the word from the 2nd array using the letters from the 1st
or backwards
don't remember the instructions
Harshal
@McQuinTrix
Mar 03 2015 07:19
thats why i told you to finis otherrwise the break you take will be of no use .. take a well superbly deserved break
Return true if the string in the first element of the array contains the string in the second element in any form
Cristián Berríos
@crisberrios
Mar 03 2015 07:21
so adadasdadagdkjahgdajkhgkjhgfajhkgfafeiou contains adfhgioue since you can extract the letters from the 1st string to make the 2nd
John Ellis
@johnmellis
Mar 03 2015 07:21
I did it
function mutation(arr) {
  if(arr[1] == 'hey'){return false;}
  if(arr[1] == 'Hello'){return true;}
  if(arr[1] == 'qrstu'){return true;}
}

mutation(['hello', 'hey']);
Cristián Berríos
@crisberrios
Mar 03 2015 07:22
lol
John Ellis
@johnmellis
Mar 03 2015 07:22
It doesn't make sense tho - regex is so specific that if I throw in spontaneous values for arr[1] - it fails
Cristián Berríos
@crisberrios
Mar 03 2015 07:22
in a sense the answer is correct since the test passes xD
regex is not the answer to this challenge
that's why it doesn't work
John Ellis
@johnmellis
Mar 03 2015 07:23
What is?
I tried using .search()
it didn't work either
anyways - going to bed. I'll tackle this tomorrow
cya guys
Cristián Berríos
@crisberrios
Mar 03 2015 07:24
good night
Harshal
@McQuinTrix
Mar 03 2015 07:24
XD
gn
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 07:24
Hmmmm
Not to brag or anything but I just solved it with a shorter code.
Shorter than I did before, anyways.
John Ellis
@johnmellis
Mar 03 2015 07:25
let's see it
damnit
I can't sleep till I see the answer
Harshal
@McQuinTrix
Mar 03 2015 07:25
i knew it
xD
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 07:26
LOL, aight. I think you should go over it again when you get some sleep.
This message was deleted
Nathan
@terakilobyte
Mar 03 2015 07:26
@johnmellis do you have screen hero?
I’d like to pair with you on this
John Ellis
@johnmellis
Mar 03 2015 07:26
Nope, found a screenshare program that works w/ ubuntu 14.04
I'll download wine sometime this week.
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 07:27
Welp, Nate gotcha.
Cristián Berríos
@crisberrios
Mar 03 2015 07:27
teamviewer works with ubuntu
John Ellis
@johnmellis
Mar 03 2015 07:27
I'm missing a dependency
too lazy to find it tonight
Nathan
@terakilobyte
Mar 03 2015 07:28
@johnmellis hop on twitch please
Cristián Berríos
@crisberrios
Mar 03 2015 07:28
teamviewer works with ubuntu.
I’ll walk through the essence of the bonfire
quincy is in the twitch chat if you have questions
Cristián Berríos
@crisberrios
Mar 03 2015 07:29
well, cya guys, good night!
John Ellis
@johnmellis
Mar 03 2015 07:29
blah
Nathan
@terakilobyte
Mar 03 2015 07:29
blah?
John Ellis
@johnmellis
Mar 03 2015 07:29
flash player isn't working inchromium
Nathan
@terakilobyte
Mar 03 2015 07:30
ugh
John Ellis
@johnmellis
Mar 03 2015 07:30
I'm on a new ubuntu setup and haven't walked all the way through it
let me get on my work machine
Nathan
@terakilobyte
Mar 03 2015 07:30
do you have chrome?
John Ellis
@johnmellis
Mar 03 2015 07:30
brb
Nathan
@terakilobyte
Mar 03 2015 07:30
ok
Harshal
@McQuinTrix
Mar 03 2015 07:30
johnmellis just shook the whole room xD
John Ellis
@johnmellis
Mar 03 2015 07:33
alright, I'm back
and in twitch
Nathan
@terakilobyte
Mar 03 2015 07:36
ok
Harshal
@McQuinTrix
Mar 03 2015 07:46
i told ya to use sort .. :shipit:
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 07:48
function mutation(arr) {
  var matcher = new RegExp("[" + arr[1] + "]", "ig");
  return arr[0].match(matcher).length === arr[1].length;
}
mutation(['hello', 'hey']);
How I solved it.
Well, this is my 2.5 solution anyways.
Harshal
@McQuinTrix
Mar 03 2015 07:49
function mutation(arr) {
  var reg = "/["+arr[1]+"]/g";
  console.log(reg);
  return arr[0].match(reg);
}

mutation(['hello', 'hey']);
why would this not work ? :{
it gives out null
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 07:50
Because you need to match every letter from the second index of the array.
Oh.
not only that but you created a string, not a RegExp object
you need to use new RegExp(); to create a new regex object from a variable.
Harshal
@McQuinTrix
Mar 03 2015 07:51
last time i used this in match and it worked ..
alrigtttt let me see that ..
maybe i did something different .. i will check it
your solution is awesome too ;)
John Ellis
@johnmellis
Mar 03 2015 08:12
@terakilobyte johnmellis
Nathan
@terakilobyte
Mar 03 2015 08:12
thanks for the feedback guys
and hopefully my explanation on stream helped?
I really, truly, give a shit
Harshal
@McQuinTrix
Mar 03 2015 08:13
ofcourse Nathan .. you are best :shipit:
John Ellis
@johnmellis
Mar 03 2015 08:15
@terakilobyte +1
Kiy-Hong Tang
@kiytang
Mar 03 2015 09:55
Just working through express middleware and wondering would would be defined as a non-static file?
Cristián Berríos
@crisberrios
Mar 03 2015 13:43
good morning
John Ellis
@johnmellis
Mar 03 2015 14:34
@kiytang API calls to a Database
you usually serve your entire website using the express static middleware, then reserve your other routes in express for api calls
Kiy-Hong Tang
@kiytang
Mar 03 2015 15:11
Thanks @johnmellis-very helpful indeed
Cristián Berríos
@crisberrios
Mar 03 2015 15:47
@kiytang a non-static file would be, for example, an on-demand generated page
Thiago Ferreira
@ThiagoFerreir4
Mar 03 2015 20:15
any tips on that chunky monkey bonfire?
Ryan Malm
@Rybar
Mar 03 2015 20:25
array.prototype has methods that will return a slice of an array.. you might start there. ;)
Thiago Ferreira
@ThiagoFerreir4
Mar 03 2015 20:27
txs buddy
Oliver
@Dadsaster
Mar 03 2015 21:30
I don't know who to direct this towards but IMO on the "Map the Debris" bonfire - the constants and the equation required should be provided in the description. I guess there is an argument for it being more "real-world" by making us have to look up everything but that aspect seems outside of coding to me.
John Ellis
@johnmellis
Mar 03 2015 21:31
try wolfram alpho for the formulas
@terakilobyte is big on that site
Oliver
@Dadsaster
Mar 03 2015 21:32
I completed the bonfire - it's just a suggestion
Chris Dziewa
@chrisdziewa
Mar 03 2015 21:47
Has anyone here finished the final Bonfire challenge "No repeats please"?
Oliver
@Dadsaster
Mar 03 2015 22:14
yes
Oliver
@Dadsaster
Mar 03 2015 22:26
@chrisdziewa yes
Nathan
@terakilobyte
Mar 03 2015 22:27
because wolfram alpha is, in fact, the shit
Oliver
@Dadsaster
Mar 03 2015 22:28
Okay - at least provide the formula then - I didn't get that on wolfram alpha
Nathan
@terakilobyte
Mar 03 2015 22:29
formula for?
oh, use the one on wikipedia
is why I linked the article
Luke
@Lukukas
Mar 03 2015 22:29
feeling stupid
assert.deepEqual(telephoneCheck("(6505552368)"), false);AssertionError:expected true to deeply equal false
why is this not considered a phone number?
it follows 123 123-1234 pattern so shouldn't it be true and not false?
Nathan
@terakilobyte
Mar 03 2015 22:31
it’s 2 PI Sqrt(SMA (avgAlt from center of orbited body)^3 / GM)
off the top of my head
but verify for sure on wikipedia
I use wolfram alpha for values
Luke
@Lukukas
Mar 03 2015 22:31
I found the one on the dummies to be more helpful actually
lol
it basically says the same thing as the wikipedia article but it made more sense to me
Nathan
@terakilobyte
Mar 03 2015 22:35
awesome :)
if you guys find that link more useful I’ll include that link as well
in the bonfire description
Phillip Ventura
@fvntr
Mar 03 2015 22:38
@chrisdziewa wanna pair?
Cristián Berríos
@crisberrios
Mar 03 2015 22:39
@terakilobyte the only confussion I see is that Wikipedia refers to avgAlt as including the earth radius
and equivalent to semi-major axis for this case
that had me wondering for a while
well... not quite like that
but the wording might mislead you
Average distance[edit]
It is often said that the semi-major axis is the "average" distance between the primary focus of the ellipse and the orbiting body. This is not quite accurate, as it depends on what the average is taken over.

averaging the distance over the eccentric anomaly (q.v.) indeed results in the semi-major axis.
I took average distance for average altitude
Luke
@Lukukas
Mar 03 2015 22:54
assert.deepEqual(telephoneCheck("(6505552368)"), false);AssertionError:expected true to deeply equal false
why is this not considered a phone number?
it follows 123 123-1234 pattern so shouldn't it be true and not false?
Cristián Berríos
@crisberrios
Mar 03 2015 23:00
555-555-5555, (555)555-5555, (555) 555-5555, 555 555 5555, 5555555555, 1 555 555 5555
I don't see the pattern listed
Luke
@Lukukas
Mar 03 2015 23:02
5555555555
it's just all the numbers crammed together
Cristián Berríos
@crisberrios
Mar 03 2015 23:04
but in this case, you have to specifically test for the patterns
that's what makes it harder
Luke
@Lukukas
Mar 03 2015 23:04
but I don't understand what makes this pattern wrong
it has 10 digits
Cristián Berríos
@crisberrios
Mar 03 2015 23:05
it has parenthesis
Luke
@Lukukas
Mar 03 2015 23:05
it doesn't need parenthesis
to be valid
this doesn't have parenthesis
it has 10 digits
Cristián Berríos
@crisberrios
Mar 03 2015 23:05
assert.deepEqual(telephoneCheck("(6505552368)"), false);
Luke
@Lukukas
Mar 03 2015 23:05
10 digits makes a phone number
aha!
I see them now
so for the phone numbers it can't start with a symbol character?
this makes way more sense now
Hannan Ali
@abdulhannanali
Mar 03 2015 23:08
@crisberrios Can you help me with the symmetric difference problem? I have tried some ideas but it's not working.
Cristián Berríos
@crisberrios
Mar 03 2015 23:09
see the wikipedia page
it's a little troublesome
because if you have the elements in A but not B, then it has to be removed
Hannan Ali
@abdulhannanali
Mar 03 2015 23:10
@crisberrios I have seen it. But I am thinking about how to approach this problem
with 3 sets
I just can't figure out
Cristián Berríos
@crisberrios
Mar 03 2015 23:10
but then if they are in C it's backwards
see the wikipedia entry
and look at the venn's diagram
Luke
@Lukukas
Mar 03 2015 23:11
yeah, there's also a great venn diagram video about it on youtube that I found helpful.
btw thanks @crisberrios for your help]
Hannan Ali
@abdulhannanali
Mar 03 2015 23:12
This message was deleted
@Lukukas I've seen it thanks
Nathan
@terakilobyte
Mar 03 2015 23:20
@crisberrios I can see how it might be misleading, that’s why I included the earth’s radius as a data point
Hannan Ali
@abdulhannanali
Mar 03 2015 23:21
@terakilobyte One friendly Question... Do you sleep?
Nathan
@terakilobyte
Mar 03 2015 23:22
For a two body equation where one is massively larger than the other I’ve never seen the focus defined as anything but the center of the orbited body
I slept last night @abdulhannanali
Hannan Ali
@abdulhannanali
Mar 03 2015 23:23
@terakilobyte You provided the GM value which made everything very easy in that problem.
Nathan
@terakilobyte
Mar 03 2015 23:31
@abdulhannanali re your sleep question. I don’t like sleeping a lot. We sleep a 3rd of our lives. If I get 4-5 hours a night I might sacrifice 5 years from lifespan but I’ve gained about 10 years of awake time. And I’ll gladly give up 5 years at the end anyway.
Cristián Berríos
@crisberrios
Mar 03 2015 23:32
not a bad way of thinking
at the end is how much you live, not how much you last
Nathan
@terakilobyte
Mar 03 2015 23:32
^
Hannan Ali
@abdulhannanali
Mar 03 2015 23:34
@terakilobyte Really Inspiring!
I must sleep less too.
Darryl Dixon - Piece Digital
@piecedigital
Mar 03 2015 23:43
I already don't sleep enough. issue is I dont have all of my brain without enough sleep LOL
Hannan Ali
@abdulhannanali
Mar 03 2015 23:43
@piecedigital True that