These are chat archives for FreeCodeCamp/Help

23rd
Sep 2017
Albert Cardona II
@daddycardona
Sep 23 2017 00:09
what up yall ;)
Johnny
@JohnnyBizzel
Sep 23 2017 00:16
@daddycardona NodeJs with Express, but facebook took over
Albert Cardona II
@daddycardona
Sep 23 2017 00:20
LOL
Yeah i am not even close to looking into node ;)
Johnny
@JohnnyBizzel
Sep 23 2017 00:33
@daddycardona It's not too difficult. There are a few concepts to grasp but once you get them it's ok. I've done the NodeJs challenges but I'm going through some courses on Pluralsight.
Albert Cardona II
@daddycardona
Sep 23 2017 00:34
@JohnnyBizzel
@JohnnyBizzel I am trying these challenges and trying to use the regex man is that confusing to me but I am almost getting the hang of it, however I am thinking about going to lynda or treehouse more so treehouse I only heard good things from them :)
Johnny
@JohnnyBizzel
Sep 23 2017 00:36
@daddycardona Are you using https://regexr.com/ ?
Or https://regex101.com/ ?
Albert Cardona II
@daddycardona
Sep 23 2017 00:37
No I was using a different one
Johnny
@JohnnyBizzel
Sep 23 2017 00:37
There are a few out there.
Albert Cardona II
@daddycardona
Sep 23 2017 00:37
Johnny
@JohnnyBizzel
Sep 23 2017 00:38
It takes time to get used to regex. Totally different language!
Albert Cardona II
@daddycardona
Sep 23 2017 00:38
but I have heard many youtube users use regex101 so I might have to try it lol
I see lol
be back later about to eat and watch a show :)
Johnny
@JohnnyBizzel
Sep 23 2017 00:46
@daddycardona Take it easy. I'm going to bed now. zzzz
aRtoo
@artoodeeto
Sep 23 2017 01:07

hellow fam
i got the solution correct now
but i have a question
my first solution is this. i got the requirements correct except for the other one.
bob instanceof Person should return true. im getting this incorrect.

my first solution:

 /*var first = firstAndLast.split(' ')[0];
    var last = firstAndLast.split(' ')[1];

    return  {
      getFullName: function() {
        var fullName = first + ' ' + last;
        return fullName;
      },

      getFirstName: function() {
        return first;
      },

      getLastName: function() {
        return last;
      },

      setFirstName: function(newFirst) {
         first = newFirst;
      },

      setLastName: function(newLast) {
         last = newLast;
      },

      setFullName: function(newFullname) {
        first = newFullname.split(' ')[0];
        last = newFullname.split(' ')[1];
         //firstAndLast = newFullname;
      }
    };*/

var bob = new Person('Bob Ross');
bob.getFullName();

but on my 2nd solution
this is my 2nd solution i got everything correct. i just used the .this keyword. i dont know why. i just followed the given sample that was initialize

var Person = function(firstAndLast) {

    var fname = firstAndLast.split(' ')[0];
    var lname = firstAndLast.split(' ')[1];

    //Complete the method below and implement the others similarly
    this.getFullName = function() {
      var fullname = fname + ' ' + lname;
      return fullname;
    };

    this.getFirstName = function() {
      return fname;
    };

    this.getLastName = function() {
      return lname; 
    };

    this.setFirstName = function(newFirst) {
      fname = newFirst;
    };

    this.setLastName = function(newLast) {
      lname = newLast;
    };

    this.setFullName = function(newFull) {
      fname = newFull.split(' ')[0];
      lname = newFull.split(' ')[1];
    };

};


var bob = new Person('Bob Ross');
bob.setFullName('bruh haa');
bob.getFullName();
Bob Guo
@boblao0714
Sep 23 2017 02:46
hey guys how to change the font size of an element?
plz
Henry
@GitHub-Henry
Sep 23 2017 02:47
css-selector {font-size: 1em;}
Bob Guo
@boblao0714
Sep 23 2017 02:53
ok thanks
Darren
@DarrenfJ
Sep 23 2017 04:36
evening fCC
how goes the coding?
Henry
@GitHub-Henry
Sep 23 2017 04:37
@DarrenfJ ok here, do you know fiddler?
@DarrenfJ how goes it for you?
Darren
@DarrenfJ
Sep 23 2017 04:38
naw... what is it? some kinda sandbox?
goodGood. quiet night.. gonna go do some codecademy exercsies or something :D
Henry
@GitHub-Henry
Sep 23 2017 04:39
@DarrenfJ it's a network sniffer type of tool, like wireshark
Darren
@DarrenfJ
Sep 23 2017 04:39
brownies for helping out above though
thanks @GitHub-Henry
CamperBot
@camperbot
Sep 23 2017 04:39
darrenfj sends brownie points to @github-henry :sparkles: :thumbsup: :sparkles:
:cookie: 359 | @github-henry |http://www.freecodecamp.com/github-henry
Darren
@DarrenfJ
Sep 23 2017 04:39
what are yah doing with it? You learning networks?
Henry
@GitHub-Henry
Sep 23 2017 04:39
thanks, good luck with your exercises
@DarrenfJ it let's you intercept api requests
working with api's
Darren
@DarrenfJ
Sep 23 2017 04:40
cool
what're you trying to do?
just curious
Henry
@GitHub-Henry
Sep 23 2017 04:41
@DarrenfJ i'm getting a security error from an api when i start using fiddeler, i wondered what i needed to do to stop fiddler from triggering the security error.
seems like the api detects the 'man in the middle' security breach, which is what fiddler is doing.
good for the api, bad for debugging
not that i have a problem, just wanting to use the tool
Manish Giri
@Manish-Giri
Sep 23 2017 04:45
@DarrenfJ :wave:
Darren
@DarrenfJ
Sep 23 2017 04:46
@GitHub-Henry ah cool... sounds like a challenge
manish! :D
Manish Giri
@Manish-Giri
Sep 23 2017 04:46
saw your outing pics, very nice!
esp the lill doggos
Darren
@DarrenfJ
Sep 23 2017 04:48
oh yah.. we had a chance last minute to grab a cottage..
i am here
actually called Bob's lake
the lake, of bob
and i owe yah a thank from yesterday i missed
thanks @Manish-Giri
CamperBot
@camperbot
Sep 23 2017 04:49
darrenfj sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6566 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Sep 23 2017 04:49
niice
not far from Rochester in NY
Darren
@DarrenfJ
Sep 23 2017 04:50
also, @GitHub-Henry i love how you eightball the casual room ;)
Manish Giri
@Manish-Giri
Sep 23 2017 04:50
in fact if I get to rochester, bet I could swim the lake and cross over to where you're at
:wink:
@DarrenfJ ty
CamperBot
@camperbot
Sep 23 2017 04:50
manish-giri sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2045 | @darrenfj |http://www.freecodecamp.com/darrenfj
Manish Giri
@Manish-Giri
Sep 23 2017 04:51
@DarrenfJ also, congratulations on crossing 600 days
:tada:
Henry
@GitHub-Henry
Sep 23 2017 04:51
is eightball the source of wisdom?
@DarrenfJ eightball doesn't always answer, oh well.
@DarrenfJ thanks
CamperBot
@camperbot
Sep 23 2017 04:52
github-henry sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2046 | @darrenfj |http://www.freecodecamp.com/darrenfj
Manish Giri
@Manish-Giri
Sep 23 2017 04:52
eightball is python the future
CamperBot
@camperbot
Sep 23 2017 04:52
@Manish-Giri :8ball: outlook not so good :sparkles:
Manish Giri
@Manish-Giri
Sep 23 2017 04:52
fk
(problem solved)
Darren
@DarrenfJ
Sep 23 2017 04:53
eightball is the future of balls, of eight
CamperBot
@camperbot
Sep 23 2017 04:53
@DarrenfJ :8ball: concentrate and ask again :sparkles:
Henry
@GitHub-Henry
Sep 23 2017 04:53
eightball are you the source of wisdom?
CamperBot
@camperbot
Sep 23 2017 04:53
@GitHub-Henry :8ball: yes. Definitely :sparkles:
Darren
@DarrenfJ
Sep 23 2017 04:53
:D
ooo, brb, puppies are antsty for walk.. also.. probably smell beavers or bears or something and want to explore
Darren
@DarrenfJ
Sep 23 2017 05:13
ok back
it's hella dark out here with no city lights
Manish Giri
@Manish-Giri
Sep 23 2017 05:13
how do you even have internet there
lol
Darren
@DarrenfJ
Sep 23 2017 05:14
i have no cell reception but actually pretty good internet
weird right?
Manish Giri
@Manish-Giri
Sep 23 2017 05:16
lol
yeah
quite
Henry
@GitHub-Henry
Sep 23 2017 05:17
@DarrenfJ no view of a zillion stars and milky way galaxy?
Darren
@DarrenfJ
Sep 23 2017 05:21
oh yah.. but there's a lot of tree cover you have to get right out to the dock to see that...
Henry
@GitHub-Henry
Sep 23 2017 05:25
@DarrenfJ My favorite thing is to go into the woods in mid-August, that's when you can look up and see myriads of meteors (ok, only 80 per hour), during the Perseid meteor shower.
Darren
@DarrenfJ
Sep 23 2017 05:26
@GitHub-Henry oh yah i have friends who get a bunch of people together and leave Toronto for the woods to watch it every year
Henry
@GitHub-Henry
Sep 23 2017 05:27
@DarrenfJ it's pretty cool to watch the ones that span the horizon, something special about it.
Darren
@DarrenfJ
Sep 23 2017 05:31
will have to go with them next time.. i haven't seen the meteor shower for a quite a few years now
Darren
@DarrenfJ
Sep 23 2017 05:39
@GitHub-Henry thanks for the chat.. i'm off to sleep.. have a ton of cottagre related stuff to do tomorrow
CamperBot
@camperbot
Sep 23 2017 05:39
darrenfj sends brownie points to @github-henry :sparkles: :thumbsup: :sparkles:
:cookie: 360 | @github-henry |http://www.freecodecamp.com/github-henry
Darren
@DarrenfJ
Sep 23 2017 05:40
and thanks @Manish-Giri for the corgi vids :D
CamperBot
@camperbot
Sep 23 2017 05:40
darrenfj sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
api offline
Henry
@GitHub-Henry
Sep 23 2017 05:40
@DarrenfJ thanks, good night, & enjoy the lake.
Darren
@DarrenfJ
Sep 23 2017 05:40
:D
Bhoomi Khanderia
@bhoomikhanderia
Sep 23 2017 05:45
Hi! I am trying to implement bootstrap navbar. I want my logo to be center aligned which I am not able to achieve. Can anyone please suggest the solution. Please check my code: https://codepen.io/Bhoomi/pen/QqKRQm
piteto
@piteto
Sep 23 2017 06:00
@Bhoomi-Github It depends on how you want it to look. You might try this suggestion
Lhagvasuren
@3lhagvaasuren
Sep 23 2017 07:03
https://codepen.io/3lhagvaasuren/pen/xXEoZV
guys help me. in this code i cant access to body in css.
rscales02
@rscales02
Sep 23 2017 10:52
@3lhagvaasuren looks like the css you have for body is only a black background. and the background appears to be black
What else are you trying to do with it?
rscales02
@rscales02
Sep 23 2017 11:30
function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins
  var a = " ",
      b = "-",
      newStr = "";

  for (var i = 1; i< str.length; i++){
    if (str[i] === str[i].toUpperCase() && str[i-1] !== a){
      newStr = str.slice(0,i);
    }
  }

  return newStr; //AllThe-small
}

spinalCase('AllThe-small Things');
Can someone help me understand why this returns AllThe-small and not All? according to my conditions it should be looking for uppercase letters not preceeded by a space and then slice until the Uppercase letter...
heroiczero
@heroiczero
Sep 23 2017 11:35
@rscales02 I suggest you use regexp
rscales02
@rscales02
Sep 23 2017 11:37
I was starting to move in that direction...
Bashir Harrell
@bookofbash
Sep 23 2017 11:39
Anyone around?
I'm having trouble with node
Justin25
@Justin25
Sep 23 2017 11:42
I might be able to help @bookofbash
What's the problem?
heroiczero
@heroiczero
Sep 23 2017 11:43
@rscales02 You do know you are not checking when i=0 so it is not checking for A in the All
Bashir Harrell
@bookofbash
Sep 23 2017 11:43
const fs = require("fs");
const path = require("path");
const ext = "extType."+(process.argv[3]);
const extname = path.extname(ext);
const directory = '/tmp/_learnyounode_3885';
fs.readdir( directory, function callback(err,files){
    files.forEach(function(file) {
  console.log(file);
});
  });
I am trying to filter by extension, but I cant even get the files to print before filtering them
rscales02
@rscales02
Sep 23 2017 11:44
I am just trying to find the T and put in a space between All and The
heroiczero
@heroiczero
Sep 23 2017 11:46
@rscales02 you do know str[i-1] !== a will be true for every character other than space
Justin25
@Justin25
Sep 23 2017 11:48
@bookofbash Add if (err) { throw err; }
before the forEach to see if you get an error
rscales02
@rscales02
Sep 23 2017 11:49
yeah, so I am looking for the uppercase letters not preceeded by a space in the example AllThe-small Things that would be T
(at least the first T...)
Bashir Harrell
@bookofbash
Sep 23 2017 11:50
@Justin25 ok
Justin25
@Justin25
Sep 23 2017 11:52
Did it give an error
Bashir Harrell
@bookofbash
Sep 23 2017 11:53
Yea, no such file in directory
I figured it out thanks. my directory name was changing because thats how learnyounode works. So, I was using a directory that didnt exist
fs.readdir( directory, function callback(err,files){
    if (err){throw err;}
    files.forEach(function(file) {
  console.log(file);
});

    });
@Justin25 is it considered good practice to put the if (err) {throw err;}?
Justin25
@Justin25
Sep 23 2017 11:55
Yes, that way you know if something went wrong
heroiczero
@heroiczero
Sep 23 2017 12:02
@rscales02 try throwing a break in there
@rscales02 like
function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins
  var a = " ",
      b = "-",
      newStr = "";

  for (var i = 1; i< str.length; i++){
    if (str[i] === str[i].toUpperCase() && str[i-1] !== a){
      newStr = str.slice(0,i);
       break;
    }
  }

  return newStr; //AllThe-small
}
rscales02
@rscales02
Sep 23 2017 12:04
nice, thanks @heroiczero !
CamperBot
@camperbot
Sep 23 2017 12:04
rscales02 sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1764 | @heroiczero |http://www.freecodecamp.com/heroiczero
Bashir Harrell
@bookofbash
Sep 23 2017 12:16
thanks @Justin25 Helped a bunch I just finished the exercise. Now on to the next one
CamperBot
@camperbot
Sep 23 2017 12:16
bookofbash sends brownie points to @justin25 :sparkles: :thumbsup: :sparkles:
:cookie: 307 | @justin25 |http://www.freecodecamp.com/justin25
rscales02
@rscales02
Sep 23 2017 12:16
Got to love writing code that only works for on case in particular lol
Justin25
@Justin25
Sep 23 2017 13:15
@rscales02 You mean all of my code?
rscales02
@rscales02
Sep 23 2017 13:16
Haven't seen all of yours, but definitely most of mine!
Justin25
@Justin25
Sep 23 2017 13:17
Lol, I've been trying to get better at making reusable code, but it's definitely going to take some time.
rscales02
@rscales02
Sep 23 2017 13:19
any idea how to insert dashes so thisIsSpinalTap becomes this-Is-Spinal-Tap? I have figured out how to spot it with /[a-z][A-Z]/ but I can't think how to put those dashes in
rscales02
@rscales02
Sep 23 2017 13:35
the only thing I can think of is to slice(0, str.search(/[a-z][A-Z]/)) + "-", but I can't figure out how to loop through the str for each case...
korzo
@korzo
Sep 23 2017 13:38
@rscales02 isn't str.replace or str.split better option?
rscales02
@rscales02
Sep 23 2017 13:40
I can't figure out what to replace with. Let me play with split and concat I guess...
korzo
@korzo
Sep 23 2017 13:41
@rscales02 in replace you can use backreference
rscales02
@rscales02
Sep 23 2017 13:51
much closer... thanks @korzo
CamperBot
@camperbot
Sep 23 2017 13:51
rscales02 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 533 | @korzo |http://www.freecodecamp.com/korzo
rscales02
@rscales02
Sep 23 2017 13:54
got it! I cannot believe that what has taken me about 6 hours to figure out is literally 2 lines of code though :laughing:
korzo
@korzo
Sep 23 2017 13:55
@rscales02 And you can use backreference even without function like
str.replace(/your regex/g, '$1')
and $1 will be replaced with result from () in regex
rscales02
@rscales02
Sep 23 2017 13:56
newStr = str.replace(matches, "$1 $2").replace(/\s/g, b).replace(/_/g, b)
was the magic line of pain in my dick :smile:
mithun
@dmithun
Sep 23 2017 14:14
someone plz help me
how am i gonna learn json and ajax????????
artbohr
@artbohr
Sep 23 2017 14:24
@dmithun I guess it's with Jquery library, just google or search on youtube for "jquery json tutorial"
mithun
@dmithun
Sep 23 2017 14:26
i searched about it but not getting enough resource :(
artbohr
@artbohr
Sep 23 2017 14:27
@dmithun this 2 links, it's basicly all you need for fcc json/ajaq related exercises:
http://api.jquery.com/jquery.getjson/
http://api.jquery.com/jquery.ajax/
mithun
@dmithun
Sep 23 2017 14:28
thanks @artbohr :)
CamperBot
@camperbot
Sep 23 2017 14:28
dmithun sends brownie points to @artbohr :sparkles: :thumbsup: :sparkles:
:cookie: 310 | @artbohr |http://www.freecodecamp.com/artbohr
Ken Haduch
@khaduch
Sep 23 2017 14:35
@dmithun - I had a link that I saved with some tutorial videos, so I'll share that with you. Have a look at this page and good luck! Come back after you get a little insight with specific questions and you'll get help.
Mike Batista
@mbmontana
Sep 23 2017 15:25
Can anyone tell me if I'm heading in the right direction with this? I need to remove the values in arr that match any of the args.
function destroyer(arr) {
  // Remove all the values
  var args = Array.prototype.slice.call(arguments);

 var newArray;

    newArray=arr.filter(function(args){
      for (var i=0; i < arr.length; i++) {for (var j=1; j < args.length; j++)
      return arr[i] != args[j]; }
    });

 return newArray;

}


destroyer([1, 2, 3, 1, 2, 3], 2, 3);
korzo
@korzo
Sep 23 2017 15:31
@mbmontana No. args in filter callback is element of arr
rscales02
@rscales02
Sep 23 2017 15:32

function smallestCommons(arr) {
  var nextArr = [],
      total = arr[0];
  arr = arr.sort(function(a,b){return b-a;});

  for (var x = arr[0]; x >= arr[1]; x--){
    nextArr.push(x);
  } console.log(nextArr);

  for (var y = 1; y < nextArr.length; y++){
    total = nextArr[y]*total/gcd(nextArr[y],total);
  }

  return total;
}

function gcd(x,y){
  var newArr = [];
  for (var i = 1; i < y; i++){
    if (x%i == 0 && y%i == 0)
      newArr.push(i);
  }
  return newArr[newArr.length-1];
}


smallestCommons([5,1]);
Can someone tell me why nextArr gets logged in my console 7 times the first 5 times they return identical [5, 4, 3, 2, 1], followed by [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] and [23, 22, 21, 20, 19, 18]
Mike Batista
@mbmontana
Sep 23 2017 15:33
@korzo Yeah I don't know what to put for the callback of the filter function. Would the function work if I leave the parentheses empty?
korzo
@korzo
Sep 23 2017 15:34
@mbmontana You put name of the variable in the parenthesis and this variable will hold current element of arr
@mbmontana In your code args will be 1, 2, 3 ...
@mbmontana in args put only rest of the arguments except arr (add one argument to slice)
korzo
@korzo
Sep 23 2017 15:39
@mbmontana
var args = Array.prototype.slice.call(arguments/*, ???*/);
return arr.filter(function(element) {
    // find if element is in args and return true/false
});
rscales02
@rscales02
Sep 23 2017 15:39
also why does that not work for [1,5] when I get identical logs in my console?
korzo
@korzo
Sep 23 2017 15:44
@rscales02 because of tests

@rscales02

smallestCommons([1, 5]) should return a number.
smallestCommons([1, 5]) should return 60.
smallestCommons([5, 1]) should return 60.
smallestCommons([1, 13]) should return 360360.
smallestCommons([23, 18]) should return 6056820.

plus 1 in editor
rscales02
@rscales02
Sep 23 2017 15:46
Got it fixed :smile: !
and now I understand that too!
thanks @korzo !
CamperBot
@camperbot
Sep 23 2017 15:47
rscales02 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 535 | @korzo |http://www.freecodecamp.com/korzo
korzo
@korzo
Sep 23 2017 15:48

@rscales02 it was meant as answer to

why nextArr gets logged in my console 7 times

rscales02
@rscales02
Sep 23 2017 15:48
yup, I picked up on that
I think there is a cleaner way to do that algorithm with recursion, but I can't quite wrap my head around that
korzo
@korzo
Sep 23 2017 15:52
@rscales02 I ended up with this and it's 100x faster
// 100x faster
function smallestCommons(arr) {
  arr = arr.sort((a, b) => a-b);
  var gcd = (a, b) => a % b === 0 ? b : gcd(b, a % b); // Greatest Common Divisor 

  return Array(arr[1] - arr[0] + 1)
    .fill(0)
    .map((e, i) => arr[0] + i) // Create range
    .reduce((a, e) => (a * e)/gcd(a, e)); // Least Common Multiple
}
But I googled a lot as I had math last time 20 years ago :)
non-math version was:
function smallestCommons(arr) {
  arr = arr.sort((a, b) => a-b);  
  var range = Array(arr[1] - arr[0] + 1).fill(0).map((e, i) => arr[0] + i),      
      res;

  do {    
    res = arr[1] * arr[0]++; // we don't need arr[0] anymore
  } while(!range.every((e) => res % e === 0));

  return res;
}
rscales02
@rscales02
Sep 23 2017 15:54
How long have you been at this? I don't really understand any of that code lol
korzo
@korzo
Sep 23 2017 15:56
@rscales02 maybe 2 hours.
I started with second version, but it was slow, so I googled GCD, found some explanation with pseudo code
and replicated it using recursion. It uses variable swap
It was probably hardest challenge for me
rscales02
@rscales02
Sep 23 2017 15:57
with your var gcd does that do the same as my function gcd?
korzo
@korzo
Sep 23 2017 15:57
I think so, but using recursion instead of loop
rscales02
@rscales02
Sep 23 2017 15:58
any resources you would recommend to understand recursion better?
korzo
@korzo
Sep 23 2017 15:59
if b is 0, return b otherwise replace b with a % b and try again
rscales02
@rscales02
Sep 23 2017 16:01
I meant how long have you been learning coding? You seem about 12 steps over my head with those answers...
korzo
@korzo
Sep 23 2017 16:03
@rscales02 Recursion is very hard to grasp.
Best way is to play with it a lot.
Generally you can replace most of the counting/testing loops with recursion.
for example, here is your yesterday's code replaced with recursion
function sumPrimes(num) {
  return num < 2 ? 0 : isPrime(num)*num + sumPrimes(--num);
}

function isPrime(n, m) {
  m = m || Math.floor(Math.sqrt(n));
  return m < 2 ? true : n%m !== 0 && isPrime(n, --m);
}

sumPrimes(10);
@rscales02 I usually do 2 solutions for every challenge. I normal and one crazy using recursion/functional programming...
Mike Batista
@mbmontana
Sep 23 2017 16:12
@korzo Here's where I am now. I'm getting a syntax error saying "element.includes is not a function."
function destroyer(arr) {
  // Remove all the values
  var args = Array.prototype.slice.call(arguments, 1);

 var newArray;

    newArray=arr.filter(function(element){
      for (var i=0; i < args.length; i++)
     {if (element.includes(args[i])) {return false;} else {return true;} }
    });

 return newArray;

}


destroyer([1, 2, 3, 1, 2, 3], 2, 3);
korzo
@korzo
Sep 23 2017 16:15
@mbmontana You are using filter on arr
It's the same as [1, 2, 3, 1, 2, 3].filter()
It means that element will be :
First time 1
second time 2,
...3, 1, 2....
@mbmontana args[i] will be 2 and 3
@mbmontana but you are close
rscales02
@rscales02
Sep 23 2017 16:19
@korzo any chance you can translate this return num < 2 ? 0 : isPrime(num)*num + sumPrimes(--num); to natural language for me I do not follow what it is actuall calling/testing/returning...
Are you returning 0 if num<2?
what does : imply?
korzo
@korzo
Sep 23 2017 16:20
@rscales02
It's part of ternary operator
(condition) ? true: false
@rscales02 console.log(1 === 1 ? 'true': 'false');
Mike Batista
@mbmontana
Sep 23 2017 16:23
@korzo I did {if (element === args[i]) {return false;} else {return true;} }
}); But that still returns [1, 3, 1, 3] When the loop iterates to 3 it stops on args[0]
korzo
@korzo
Sep 23 2017 16:23
@rscales02
return num < 2 ? 0 : isPrime(num)*num + sumPrimes(--num);
If num is 1, return 0
Otherwise if num is prime , call sumPrimes with num -1 and sum result
rscales02
@rscales02
Sep 23 2017 16:25
isPrime returns a true or false, right?
korzo
@korzo
Sep 23 2017 16:25
@rscales02 isPrime returns boolean. It converts to either 1 or zero
It means that for primes it's num x 1 and for not primes num x 0
isPrime(num)*num
so not primes are 0
rscales02
@rscales02
Sep 23 2017 16:30
ok that makes more sense I guess, my head is swimming though
falsely inflated ego back to destroyed though... I still know less than nothing :smile:
korzo
@korzo
Sep 23 2017 16:32
@rscales02 for 4 it's basically
sumPrimes(4) + sumPrimes(3) + sumPrimes(2) + sumPrimes(1)
or
isPrime(4)*4 + isPrime(3)*3 + isPrime(2)*2 + 0
rscales02
@rscales02
Sep 23 2017 16:43
function findElement(arr, func) {
  var num = 0;

  for (var i = 0; i< arr.length; i++){
    num = arr[i];
    if (func === true){

      break;
    } 
  }  


  return num;
}

findElement([1, 2, 3, 4], function(num){ return num % 2 === 0; });
am I calling func incorrectly here?
korzo
@korzo
Sep 23 2017 16:44
@rscales02 yes
@rscales02 func is function
so func(arr[i])
@rscales02 try it with recursion :)
korzo
@korzo
Sep 23 2017 16:52
but filter is best fit for that
rscales02
@rscales02
Sep 23 2017 16:56
You have completely fried my brain for the day, I think...
korzo
@korzo
Sep 23 2017 16:57
@rscales02 come on, this is the simple one
you literally have it with 1 line change
rscales02
@rscales02
Sep 23 2017 17:03
That line change somehow has to include 5 other lines of code though
korzo
@korzo
Sep 23 2017 17:05
@rscales02 Code you posted needs 3 changes to pass all the tests
fix func call
replace break with something better
fix last return
rscales02
@rscales02
Sep 23 2017 17:09
I got the code to work... just looks like shit and I basically call func twice. No idea how to put it into recursion
what are other options than break?
korzo
@korzo
Sep 23 2017 17:15
@rscales02 return num;
@rscales02 and return undefined after loop
rscales02
@rscales02
Sep 23 2017 17:16
doesn't seem to need return unefined...

function findElement(arr, func) {
  var num = 0;



  for (var i = 0; i< arr.length; i++){

    if (func(arr[i]) === true){
      num = arr[i];
      return num;
    } 
  }  

}

findElement([1, 3, 5, 9], function(num) { return num % 2 === 0; });
solves it
Can you recommend any resources to better understand recursion and functional programming better?
korzo
@korzo
Sep 23 2017 17:19
@rscales02 Oh, you are right. but technically, you return undefined as you returns nothing :)
@rscales02 you should take a look at all array methods.
you are solving challenges with loops, when array methods are much better option.
also array methods are functional programming as you pass function as argument
Albert Cardona II
@daddycardona
Sep 23 2017 17:24
your variable num is inside the function find element so when you calling fucntion(num) it can't understand what num is because it is undefined outside the function findelement
@rscales02
korzo
@korzo
Sep 23 2017 17:26
@daddycardona num in function and num at the bottom are not the same.
@daddycardona Upper one is variable, at the bottom it's parameter of function
Albert Cardona II
@daddycardona
Sep 23 2017 17:27
I see that now
but how is he calling the function then it haves a function to call within that function
korzo
@korzo
Sep 23 2017 17:29
@rscales02 for example this challenge can be solved in one line using filter
@daddycardona you can pass function as a argument in javascript
Albert Cardona II
@daddycardona
Sep 23 2017 17:30
I know that @korzo just looks confusing to me how its done her
here lOL
rscales02
@rscales02
Sep 23 2017 17:32
so something like num = arr.filter(func())
but how do I pass each number from the array into the func?
Albert Cardona II
@daddycardona
Sep 23 2017 17:35
arr.filter does that for you so arr.filter(function(arg){}):
korzo
@korzo
Sep 23 2017 17:35
@rscales02 Yes,
function findElement(arr, func) {
  return arr.filter(func)[0];
}
Albert Cardona II
@daddycardona
Sep 23 2017 17:36
or you can do it like that :)
korzo
@korzo
Sep 23 2017 17:36
@rscales02 func accepts one argument so have the same signature as filter's callback
and returns true/false
rscales02
@rscales02
Sep 23 2017 17:38
You are blowing my fucking mind man...
korzo
@korzo
Sep 23 2017 17:40
@rscales02 that's hardest part of functional programming/recursion...to get it :)
Albert Cardona II
@daddycardona
Sep 23 2017 17:40
damn thanks @korzo you helped me understand this recursion a little better :)
CamperBot
@camperbot
Sep 23 2017 17:40
daddycardona sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 537 | @korzo |http://www.freecodecamp.com/korzo
korzo
@korzo
Sep 23 2017 17:44
@daddycardona @rscales02 here is you code using recursion
function findElement(arr, func) {
  if(func(arr[0]) === true) {
    return arr[0];
  }

  if(arr.length === 1) {
    return undefined;
  }  
  return findElement(arr.slice(1), func);
}
Albert Cardona II
@daddycardona
Sep 23 2017 17:45
question for you @korzo let newStr = str.replace([/</g], changeIt); change it is a function why is it not letting me console.log it?
rscales02
@rscales02
Sep 23 2017 17:46
Yeah thanks for trying to help me understand better @korzo , I clearly have a long way to go before I actually get it I think. Although you have shown me that I need to completely rethink my approach... forloops were the one thing I actually understood how to use and now I have to get rid of them :frowning:
CamperBot
@camperbot
Sep 23 2017 17:46
rscales02 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 538 | @korzo |http://www.freecodecamp.com/korzo
Albert Cardona II
@daddycardona
Sep 23 2017 17:50
function convertHTML(str) {

    var newStr = str.replace([/</g], changeIt);
    console.log(newStr)
    return;


}

function changeIt(words) {
    console.log(words)


    return 'it';
}

convertHTML("Hamburgers < Pizza < Tacos"); // thewhole code
rscales02
@rscales02
Sep 23 2017 17:52
@daddycardona I don't think you are calling changeIt try adding ()
Albert Cardona II
@daddycardona
Sep 23 2017 17:52
Okay
korzo
@korzo
Sep 23 2017 17:53
@rscales02 well, array methods are practically for loops, but with cleaner code and you can chain them
for loops are way to go if you need to return from inside the loop or performance is important
@daddycardona it's ok, str.replace accepts function as 2.argument @daddycardona
@daddycardona just your regex needs some work
Albert Cardona II
@daddycardona
Sep 23 2017 17:58
I did that but now words is Undefined and when I add at (words) it became an error I thought it would catch on to that?
my regex sux i am just learning lol
I know the /g means all the instances of this < lol
so @korzo should I put that function in the other function?
korzo
@korzo
Sep 23 2017 18:00
@daddycardona function has more arguments then just words
try to console.log(arguments)
@daddycardona with regex /(<) (\w+)/g
Albert Cardona II
@daddycardona
Sep 23 2017 18:01
why should I need all that I am just trying to replace the <
korzo
@korzo
Sep 23 2017 18:01
@daddycardona Oh, I thought you should return <pizza></pizza>
Albert Cardona II
@daddycardona
Sep 23 2017 18:02
I thought if I used the [] i would be good
no I am trying to replace the < with <
&lt;
i you do &lt; without the ''` you get <
korzo
@korzo
Sep 23 2017 18:03
@daddycardona then /</g id ok
but check arguments on function changeIt
Albert Cardona II
@daddycardona
Sep 23 2017 18:04
that is what I am confused about I can't put changeIt() because it looks up nada in the parameters
korzo
@korzo
Sep 23 2017 18:06
@daddycardona of curse, it will replace it with "it";
Albert Cardona II
@daddycardona
Sep 23 2017 18:06
so if I add the function changeIt inside the function it now recognizes is as a function
nope does not do any of that
korzo
@korzo
Sep 23 2017 18:07
@daddycardona nope, you had it right str.replace([/</g], changeIt);
just regex is wrong
Albert Cardona II
@daddycardona
Sep 23 2017 18:07
I am just using this
what is wrong with it I am confused
@daddycardona Thats' why I said add console.log(arguments) at the start
Albert Cardona II
@daddycardona
Sep 23 2017 18:09
okat so I should of used the words match?
korzo
@korzo
Sep 23 2017 18:09
@daddycardona the name doesn't matter
Albert Cardona II
@daddycardona
Sep 23 2017 18:09
@korzo I did that but it is not running the function
rscales02
@rscales02
Sep 23 2017 18:10
You guys have fun... 7 hours straight and I am fried... thanks for taking all the extra time for me @korzo
CamperBot
@camperbot
Sep 23 2017 18:10
rscales02 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
api offline
Albert Cardona II
@daddycardona
Sep 23 2017 18:10
console.log(arguments) is not running the function at all
korzo
@korzo
Sep 23 2017 18:11
@daddycardona you can have
function changeIt(lol, wtf, lmao) {
    console.log(lol, wtf, lmao);
}
Albert Cardona II
@daddycardona
Sep 23 2017 18:11
LMAO
I know that why I am confused wht change it is not workign at all
korzo
@korzo
Sep 23 2017 18:11
@daddycardona post your actual code
@rscales02 glad to help. See you
Albert Cardona II
@daddycardona
Sep 23 2017 18:13
function convertHTML(str) {

    var newStr = str.replace([/</g], changeIt);
    console.log(newStr)

    function changeIt(words) {
        console.log(arguments + 'words')


        return 'it';
    }
    return newStr;
}

convertHTML("Hamburgers < Pizza < Tacos");
so I changed replac("<", changeIt ) and it does the first one so something is wrong with my regex
korzo
@korzo
Sep 23 2017 18:16
@daddycardona words === arguments[0]
what I'm trying to say is that function changeIt has more arguments that "words"
Albert Cardona II
@daddycardona
Sep 23 2017 18:17
Okay I read that but isn't that why you use the /g but either way it did not call on words at all the other way
korzo
@korzo
Sep 23 2017 18:17
@daddycardona arguments is argument object holding all parameters passed to function
@daddycardona because your regex is wrong [/</g]
change it to /</g
@korzo or /[<]/g
Albert Cardona II
@daddycardona
Sep 23 2017 18:18
okay but now I am about to change that to [<>"'] so I can change all of these
oh okay
@korzo that was what I was about to do next /[]/
once again you are a hero in this help :)
thanks @korzo
CamperBot
@camperbot
Sep 23 2017 18:19
daddycardona sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
api offline
Albert Cardona II
@daddycardona
Sep 23 2017 18:20
that did the trick I think :)
well it got all the < to it lol
korzo
@korzo
Sep 23 2017 18:20
@daddycardona [] means group of characters to search for
Albert Cardona II
@daddycardona
Sep 23 2017 18:21
yes :)
I have to do a challenge and it says we should try using regex so this is my first episode of this painful process @korzo
when you kept saying it's wrong I was like wth you talking about it's wrong until right before you posted /[]/ I was like oh maybe he means that my [/ is backwards and then bam you like /[ you dumb ass lmao I know you didn't say that but it makes the story sound better lol
korzo
@korzo
Sep 23 2017 18:23
@daddycardona :)
Mike Batista
@mbmontana
Sep 23 2017 18:45
@korzo Do I have to nest another for loop into this? I can't get the loop to iterate to the second args element.
function destroyer(arr) {
  // Remove all the values
  var args = Array.prototype.slice.call(arguments, 1);

 var newArray;

    newArray=arr.filter(function(element){
       for (var i=0; i < args.length; i++) 

       {if (element === args[i]) {return false;} else {return true;} }
});

 return newArray;

}


destroyer([1, 2, 3, 1, 2, 3], 2, 3);
korzo
@korzo
Sep 23 2017 18:48
@mbmontana you can use args.indexOf or args.includes instead of loop
Mike Batista
@mbmontana
Sep 23 2017 18:55
@korzo Thanks!
function destroyer(arr) {
  // Remove all the values
  var args = Array.prototype.slice.call(arguments, 1);

 var newArray;

    newArray=arr.filter(function(element){
     if (args.includes(element)) {return false;} return true;
    });

 return newArray;

}


destroyer([1, 2, 3, 1, 2, 3], 2, 3);
CamperBot
@camperbot
Sep 23 2017 18:55
mbmontana sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 539 | @korzo |http://www.freecodecamp.com/korzo
kiran JD
@kiranjd
Sep 23 2017 20:26
code to reverse a string. I have no idea why it's giving me an error
var s1,j;
function reverseString(str) {
var j=str.length;
for(var i=0;i<j;i++)
{
s1[i]=str[j];
j--;
}
str=s1;
return str;
}
reverseString("hello");
Gersho
@Gersho
Sep 23 2017 20:27
why do you declare s1 and j outside your function ?
kiran JD
@kiranjd
Sep 23 2017 20:27
yeah
@Gersho let me get that right
@Gersho I'm getting type error now
Manish Giri
@Manish-Giri
Sep 23 2017 20:30
is s1 supposed to be an array?
@kiranjd
kiran JD
@kiranjd
Sep 23 2017 20:30
YES
Manish Giri
@Manish-Giri
Sep 23 2017 20:30
then you need to declare it as such
otherwise it just starts out as undefined
then in your first loop iteration, you try to do undefined[0] which throws TypeError
kiran JD
@kiranjd
Sep 23 2017 20:32
yes that the exact error i got
Manish Giri
@Manish-Giri
Sep 23 2017 20:33
so do var s1 = [] at the beginning
kiran JD
@kiranjd
Sep 23 2017 20:34
yes. It's working
@Manish-Giri thank you
CamperBot
@camperbot
Sep 23 2017 20:35
kiranjd sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6567 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Sep 23 2017 20:35
:+1:
kiran JD
@kiranjd
Sep 23 2017 20:36

function reverseString(str) {
  var s1 = [];
  var j=str.length-1;
  for(var i=0;i<str.length;i++)
    {
      s1[i]=str[j];
      j--;
    }
  str=s1.join("");
  return str;
}

reverseString("hello");
Manish Giri
@Manish-Giri
Sep 23 2017 20:39
here's a shortcut -
function reverseString(str) {
  return str.split('').reverse().join('');
}
kiran JD
@kiranjd
Sep 23 2017 20:42
okay
that's good. Thanks
kiran JD
@kiranjd
Sep 23 2017 21:10
regex for matching only alphabets?
Eric Weiss
@eweiss17
Sep 23 2017 21:16
google is the best way to figure out unknown regex
Augustas
@AugustasV
Sep 23 2017 21:39
https://www.freecodecamp.org/challenges/using-objects-for-lookups

// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line

  var phoneticLookup = {
    alpha:"Adams",
    bravo:"Boston",
    charlie:"Chicago",
    delta:"Denver",
    echo:"Easy",
    foxtrot:"Frank"
  };

  // Only change code above this line   <---- WHY I NEED TO CHANGE RETURN?
  return phoneticLookup[val];
}

// Change this value to test
phoneticLookup("charlie");
its written that need to change code above this line. But i had to edit return command. I did something wrong?
Amit Patel
@AmitP88
Sep 23 2017 21:54
hey guys, I'm trying to get the click and drag functionality to work in my project and I need a little help. I followed a tutorial on here: https://code.tutsplus.com/tutorials/create-an-html5-canvas-tile-swapping-puzzle--active-10747 (I'll be modding and adding to it later) and was trying to merge it with the code I already have, and I was successful up until I implemented the onPuzzleClick(e) and updatePuzzle() functions. I know it has to do with my img variable within ctx.draw method in those two functions, but I'm not sure exactly how to resolve it. I suspect it has to do with my populator function, but I tried calling that function in the ctx.draw method instead of having img and it wouldn't work
https://codepen.io/AmitP88/pen/pWyaNY?editors=0010
Aita Kane
@aita-kane
Sep 23 2017 22:17
@lydatech Thank you
CamperBot
@camperbot
Sep 23 2017 22:17
aita-kane sends brownie points to @lydatech :sparkles: :thumbsup: :sparkles:
:star2: 2464 | @lydatech |http://www.freecodecamp.com/lydatech
Stephen James
@sjames1958gm
Sep 23 2017 22:46
@AugustasV Not really wrong. The expectation was you would write result = phoneticLookup[val];
So the existing return result; would not need to change
Ismail Hozain
@ismailhozain
Sep 23 2017 22:59
hey guys there is an issue with deploying my project to the web i am using vim and surge .sh to deploy it is it my file issue or what because it gives me a link but it looks like it is publishing an empty folder and the link does not exist
Augustas
@AugustasV
Sep 23 2017 23:07
Tiago Correia
@tiagocorreiaalmeida
Sep 23 2017 23:08
didnt it introduce you to objects before @AugustasV ?
Ismail Hozain
@ismailhozain
Sep 23 2017 23:08
hmm interesting
Tiago Correia
@tiagocorreiaalmeida
Sep 23 2017 23:08
"The sub-properties of objects can be accessed by chaining together the dot or bracket notation."
Ismail Hozain
@ismailhozain
Sep 23 2017 23:08
he means there si no hint page
is
Augustas
@AugustasV
Sep 23 2017 23:20

@tiagocorreiaalmeida

myStorage.car.inside.["glove box"]; // Change this line

at https://www.freecodecamp.org/challenges/accessing-nested-objects why this not working?

Tiago Correia
@tiagocorreiaalmeida
Sep 23 2017 23:21
"Access the myStorage object and assign the contents of the glove box property to the gloveBoxContents variable."
var gloveBoxContents = ""; // Change this line
Augustas
@AugustasV
Sep 23 2017 23:25
problem is with ["glove box"] it cant be in this way?
oh -_- thanks @tiagocorreiaalmeida
Aita Kane
@aita-kane
Sep 23 2017 23:25
hello anyone who knows a js code that remove the js apllies to the body so in that way all the body have the js applied expect the section we choose not to
CamperBot
@camperbot
Sep 23 2017 23:25
augustasv sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 359 | @tiagocorreiaalmeida |http://www.freecodecamp.com/tiagocorreiaalmeida
Tiago Correia
@tiagocorreiaalmeida
Sep 23 2017 23:27
@AugustasV you have to set the value taht comes from that object protprety to the variable they jsut gave you
Augustas
@AugustasV
Sep 23 2017 23:31
@tiagocorreiaalmeida i do something wrong?
var gloveBoxContents = "myStorage.car.inside.[glove box]";
Tiago Correia
@tiagocorreiaalmeida
Sep 23 2017 23:34
2 things you dont need a double quote around it, its not a string its an object you are acessing
so start by removing the double quotes
second
the glove box inside the[]
need some double quotes since its a string you are acessing
"glove-box"
Augustas
@AugustasV
Sep 23 2017 23:36
oh thats the thing why in example they have it
Ismail Hozain
@ismailhozain
Sep 23 2017 23:58
could anyone tell me how to sreat my own custom domain
create