These are chat archives for FreeCodeCamp/HelpJavaScript

20th
Feb 2016
Gabriel
@Zera99
Feb 20 2016 00:00
BAH
DONE
Just change .push with =
Mafalda
@otmeek
Feb 20 2016 00:00
yes :D
congrats
Gabriel
@Zera99
Feb 20 2016 00:00
Tears of success
Norman Dela Cruz
@dcnr
Feb 20 2016 00:01
ooooooooooooh
fancy named filter callback function even though it's inline!
Gabriel
@Zera99
Feb 20 2016 00:02
Eh, I just wanted to make sure I remembered what it did later
THere's NO way of defining that function outside the scope of the destroyer function is there?
Norman Dela Cruz
@dcnr
Feb 20 2016 00:02
@Zera99 grats though ahhaa :D
Gabriel
@Zera99
Feb 20 2016 00:02
I wanted to do that so badly
Norman Dela Cruz
@dcnr
Feb 20 2016 00:02
@Zera99 course you can
Gabriel
@Zera99
Feb 20 2016 00:03
How? I can't reference argsList
"We knew you could do it" Thank you FCC <3
Norman Dela Cruz
@dcnr
Feb 20 2016 00:04
@Zera99 sorry I meant to say "course you can but it will be UGLY" and won't work on FCC tester
ehekatlOf
@ehekatlOf
Feb 20 2016 00:04
@budimanfix did you get it?
Gabriel
@Zera99
Feb 20 2016 00:05
Ah. Good xD Thanks again @dcnr, also @otmeek
CamperBot
@camperbot
Feb 20 2016 00:05
zera99 sends brownie points to @dcnr and @otmeek :sparkles: :thumbsup: :sparkles:
:star: 351 | @otmeek | http://www.freecodecamp.com/otmeek
:star: 668 | @dcnr | http://www.freecodecamp.com/dcnr
budimanfix
@budimanfix
Feb 20 2016 00:05

@ehekatlOf this one couldn't work : var Car = function() {
//Change this constructor
this.wheels = 4;
this.seats = 1;
this.engines = 1;
};

//Try it out here
var myCar = new Car(3,1,2);
myCar.wheels = 3;
myCar.seats = 1;
myCar.engines = 2;

Norman Dela Cruz
@dcnr
Feb 20 2016 00:05
@Zera99 See how UGLY it is?
var argsList;

function destroyer(arr) {
  argsList = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));
  argsList.shift();
  return arr.filter(filterList);
}

function filterList(val) {
  return argsList.indexOf(val) <= -1;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3)
Gabriel
@Zera99
Feb 20 2016 00:05
I want to know who came out with the idea of calling points "Brownie points"
ehekatlOf
@ehekatlOf
Feb 20 2016 00:05
you need to pass the values
remember to assign this.value to value
and when you construct an object with your function
Gabriel
@Zera99
Feb 20 2016 00:06
Yeah.. Global variables are ugly
ehekatlOf
@ehekatlOf
Feb 20 2016 00:06
the parameters get passed as the new property values
budimanfix
@budimanfix
Feb 20 2016 00:06
@ehekatlOf Example plz
ehekatlOf
@ehekatlOf
Feb 20 2016 00:06
oh wait, I think I did mine the wrong way
lmao
var Car = function(wheels, seats, engines) {
  //Change this constructor
  this.wheels = wheels;
  this.seats = seats;
  this.engines = engines;
};

//Try it out here
var myCar = new Car(3, 1, 2);
my bad
budimanfix
@budimanfix
Feb 20 2016 00:07
@ehekatlOf I did this before and coldn't succesed
ehekatlOf
@ehekatlOf
Feb 20 2016 00:09
it should work
I just tested it
but we're allowed to change arguments right
so it should totally make sense
Norman Dela Cruz
@dcnr
Feb 20 2016 00:10
if it still won't work even though it's the correct answer, do a reset/reload/browser cache clean
Eric Mauser
@emauser2
Feb 20 2016 00:11

Pig Latin challenge; all cases work except for "glove" (and other words that start with 2 consonants)

for "glove" I get: TypeError: arr.push is not a function

function translate(str) {

  if (vowel(str.charAt(0))){
    str = str + 'way';
    return str;
  }
  var arr = str.split('');
  var move = [];

  for (j=1; j<str.length; j++){
    if (!vowel(arr[0])){
      move.push(arr[0]);
      arr.shift();

    }else{break;}
      arr.push(move);
      arr=arr.join('') + 'ay';
  }

  return arr;
}

function vowel(letter){
    var vowels = ["a", "e", "i", "o","u", "A", "E","I", "O", "U"];
    for (i=0; i<vowels.length; i++){
    if (letter == vowels[i]){
      return true;
    }
  }
  return false;

}

translate("glove");
ehekatlOf
@ehekatlOf
Feb 20 2016 00:11
so does anyone know if there's a way to pass form values in real time?
budimanfix
@budimanfix
Feb 20 2016 00:11
@ehekatlOf Yess!! Worked!! I changed Funtion from ( )
ehekatlOf
@ehekatlOf
Feb 20 2016 00:11
haha, good stuff dude
it makes sense right?
pass arguments as this
budimanfix
@budimanfix
Feb 20 2016 00:11
@ehekatlOf thank you :+1:
CamperBot
@camperbot
Feb 20 2016 00:11
budimanfix sends brownie points to @ehekatlof :sparkles: :thumbsup: :sparkles:
:star: 220 | @ehekatlof | http://www.freecodecamp.com/ehekatlof
budimanfix
@budimanfix
Feb 20 2016 00:13
@ehekatlOf Yess, I was though should put any nomber on that :smile:
Martin Norberg
@Catgroove
Feb 20 2016 00:15
What's the difference in writing function constructorName() {} vs var constructorName = function() {}
Clark Arnold
@clarkarnold
Feb 20 2016 00:21
Hi all, I am working on smallest common multiple and am having trouble..
Anyone got any advice?
function smallestCommons(arr) {
  var ar = arguments[0].sort(function(a,b) {return a+b;});
  var myArr=[];
  var final = [];
  var end = [];
  for (var i=ar[0]; i>=ar[1]; i--) {
    myArr.push(i);
  }
  for (var n=1; n<10; n++) {
    final.push(ar[0]*n);
  }
  for (var x=ar[0]; x <=ar[1]; x++) {
    if (final[x]%myArr[1]) {
      end.push(final[x]);
    }
  }
  return end;
}
Tom Hodgkinson
@LibLogic
Feb 20 2016 00:24
I did a recursive solution for "Sum All Primes" . My solution returns the correct value, but it doesn't pass?? Any body see anything wrong?
var primesAll = [];
var primesTotal;
function sumPrimes(num) {

    var prime = [];
    if (num <= 1) {
        return;
    }

    for ( var i = 2; i <= num; i++ ) {
        if ( num % i === 0 ) {
            prime.push(i);

        }
        if ( prime[0] === num ) {
            primesAll.push(prime[0]);
        }
    }
    primesTotal = primesAll.reduce(function(all, item) {
        all += item;
        return all;
    }, 0);

    sumPrimes(num - 1);

    //console.log(num); //stack unwinds here
    return primesTotal;
}

sumPrimes(977);
I wonder if I should report a bug
Orestis Gklavas
@oglavas
Feb 20 2016 00:30
@emauser2 Could you try to define a new variable instead of : arr=arr.join('') + 'ay';
@emauser2 i.e. var string2 = ...
Eric Mauser
@emauser2
Feb 20 2016 00:35
@oglavas i at least got an answer when i did it that way. it is not even close to correct, but i may be able to fix it from there. lemme see
Orestis Gklavas
@oglavas
Feb 20 2016 00:36
@emauser2 It probably had issues going from array to int
Eric Mauser
@emauser2
Feb 20 2016 00:38
@oglavas would it ever make it to an int? I was thinking the farthest it should have changed is just from an array of [g,l,o,v,e] to an array of [o,v,e]
Orestis Gklavas
@oglavas
Feb 20 2016 00:39
@LibLogic I see some strange things in your code, I must admit...I don't like the first for loop (it's 2.30 a.m. here so my comprehension skills are a bit low, please be patient)... First of all: If num%i === 0, then it's not a prime. Also, you only need to check up to num/2 and not up to num, since a number cannot be divided by one larger than its half.
@emauser2 Sorry, I meant String not int
Michelle
@Michelle2016
Feb 20 2016 00:40

What am I missing???

// Setup
var myPlants = [
{
type: "flowers",
list: [
"rose",
"tulip",
"dandelion"
]
},
{
type: "trees",
list: [
"fir",
"pine",
"birch"
]
}
];

// Only change code below this line

var secondTree = myPlants.trees1;

Eric Mauser
@emauser2
Feb 20 2016 00:41

@oglavas now I'm getting a result of: oveg,lg,lay

any thoughts?

  function translate(str) {

  if (vowel(str.charAt(0))){
    str = str + 'way';
    return str;
  }
  var arr = str.split('');
  var move = [];
  var arr2;
  for (j=0; j<str.length; j++){
    if (!vowel(arr[0])){
      move.push(arr[0]);
      arr.shift();

    }else{break;}
      arr.push(move);
      arr2=arr.join('') + 'ay';
  }

  return arr2;
}

function vowel(letter){
    var vowels = ["a", "e", "i", "o","u", "A", "E","I", "O", "U"];
    for (i=0; i<vowels.length; i++){
    if (letter == vowels[i]){
      return true;
    }
  }
  return false;

}

translate("glove");
@Michelle2016 what waypoint is that?
Orestis Gklavas
@oglavas
Feb 20 2016 00:42
@emauser2 Yes, I tried it too and saw it...let me get a closer look
Tom Hodgkinson
@LibLogic
Feb 20 2016 00:42
@oglavas num % i === 0 is true if i is in fact num ...this code is probably a little tricky. At least it was for me.
Michelle
@Michelle2016
Feb 20 2016 00:42
Accessing Nested Arrays in JSON
Jay
@jayleach
Feb 20 2016 00:42

Hey, everyone, if you all don't mind, I could use some help. Here is my code, why isn't it working?

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line

myNoun = wordBlanks[0];
myAdjective = wordBlanks1;
myVerb = wordBlanks2;
myAdverb = wordBlanks[3];

result = "The " + myNoun + " was " + myAdjective + " and " + myVerb + " very " + myAdverb + ".";

// Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");

Alex9911
@Alex9911
Feb 20 2016 00:43
what's the challenge? @jele233
Michelle
@Michelle2016
Feb 20 2016 00:44
Hello @jele233 you need to concatenate as well, yes?
Tom Hodgkinson
@LibLogic
Feb 20 2016 00:44
@oglavas This code give the correct answer as far as I've tested...it returns the right answer but the editor won't let it pass
Jay
@jayleach
Feb 20 2016 00:44

"We will now use our knowledge of strings to build a "Mad Libs" style word game we're calling "Word Blanks". You will create an (optionally humorous) "Fill in the Blanks" style sentence.

You will need to use string operators to build a new string, result, using the provided variables: myNoun, myAdjective, myVerb, and myAdverb.

You will also need to provide additional strings, which will not change, in between the provided words." That is te challenge

budimanfix
@budimanfix
Feb 20 2016 00:44
How to solve this challenge guys?? : freecodecamp.com/challenges/make-object-properties-private
Michelle
@Michelle2016
Feb 20 2016 00:45
@jele233 You need to create the result
@jele233 by this I mean that you are needing to provide additional strings, between the provided words as it says in the directions.
Orestis Gklavas
@oglavas
Feb 20 2016 00:46
@LibLogic : I think you are mistaken...num%i === 0 would be true if num is a multiple of i. The % operator gives the division remainder
Eric Mauser
@emauser2
Feb 20 2016 00:46
@Michelle2016 remember that MyPlants is an array, so you need to specify which element in the array you accessing using bracket notation. Then you can add the .list and specify which element from the list using bracket notation
Charles Chung
@chulmo
Feb 20 2016 00:46
Can someone help?
 var obj = {
   1: [4, 5, 6],
   2: [2, 3, 4],
   3: [1, 2, 3],
   //etc....
 }

 for (var x = 0; x <= foo.length - 1; x++) {
   if (
     //how do you check x[i] against every array in the object
     //without knowing how many properties exist?
   ) {
     return "i found something in the object"
   }
 }
Michelle
@Michelle2016
Feb 20 2016 00:48
@emauser2 Is it var secondTree = myPlants2?
"Jake"
@JacobHorne
Feb 20 2016 00:48
Error, You should use the == operator

// Setup
function myTest(Val) {
if (Val == 12) { // Change this line
return "Equal";
}
return "Not Equal";
}

// Change this value to test
myTest(12);

Michelle
@Michelle2016
Feb 20 2016 00:48
@jele233 Your code needs to be in the result line.
Orestis Gklavas
@oglavas
Feb 20 2016 00:48
@LibLogic : I'll have to check it tomorrow with a clear head. For now, subtract 1. I think this exercise does not want to count 1 as a prime
budimanfix
@budimanfix
Feb 20 2016 00:48

var Bike = function() {

// Only change code below this line.
var speed = 10;
this.getGear = function(shange);
};

"Jake"
@JacobHorne
Feb 20 2016 00:50
in my function, I am using ==
Eric Mauser
@emauser2
Feb 20 2016 00:50
@Michelle2016 it should be myPlants1.list1
this gives you the tree object (second element in myPlants array) and the second tree in the list (the second element in the list array)
Tom Hodgkinson
@LibLogic
Feb 20 2016 00:51
@oglavas so for example using the number 13 (which is prime), when "i is 13 it pushes i to the prime array...which is what I want here. yea I think someone would have to test it...(pretty sure it works) I start the loop at 2 so that 1 does not get counted....thanks for looking though.Thing got complicated because I was determined to use recursion to solve it...
CamperBot
@camperbot
Feb 20 2016 00:51
liblogic sends brownie points to @oglavas :sparkles: :thumbsup: :sparkles:
:star: 298 | @oglavas | http://www.freecodecamp.com/oglavas
Michelle
@Michelle2016
Feb 20 2016 00:52
@emauser2 It's funny I had something very close instead of list I had trees. Thank you for your help!!!
CamperBot
@camperbot
Feb 20 2016 00:52
michelle2016 sends brownie points to @emauser2 :sparkles: :thumbsup: :sparkles:
:star: 278 | @emauser2 | http://www.freecodecamp.com/emauser2
Orestis Gklavas
@oglavas
Feb 20 2016 00:52
@emauser2 I may be mistaken, but from a very quick glance, it seems that the problem COULD occur when you push the move array into the arr array. Perhaps you are creating a secon dimension in the arr array
Tom Hodgkinson
@LibLogic
Feb 20 2016 00:53
Someone said there is a code review room, where can I find it (or how do I get to it)
those are all of the different rooms for FCC
Michelle
@Michelle2016
Feb 20 2016 00:56
@jele233 How are you doing with it?
Tom Hodgkinson
@LibLogic
Feb 20 2016 00:56
@emauser2 thanks
CamperBot
@camperbot
Feb 20 2016 00:56
liblogic sends brownie points to @emauser2 :sparkles: :thumbsup: :sparkles:
:star: 279 | @emauser2 | http://www.freecodecamp.com/emauser2
Eric Mauser
@emauser2
Feb 20 2016 00:56
@oglavas you are right! it is creating a 2D array
Orestis Gklavas
@oglavas
Feb 20 2016 01:00
@LibLogic I am starting to think that perhaps some of your code may be a bit bypassed during the iterations...for example, you never reach the final return statement
Eric Mauser
@emauser2
Feb 20 2016 01:00
@oglavas thank you! I needed to use .concat instead of .push
CamperBot
@camperbot
Feb 20 2016 01:00
emauser2 sends brownie points to @oglavas :sparkles: :thumbsup: :sparkles:
:star: 299 | @oglavas | http://www.freecodecamp.com/oglavas
Orestis Gklavas
@oglavas
Feb 20 2016 01:00
or push(move[0])
Tom Hodgkinson
@LibLogic
Feb 20 2016 01:01
@oglavas My problem is that the code works but the editor won't let it pass..I haven't found a test where it provides the wrong answer
Charles Chung
@chulmo
Feb 20 2016 01:02
Is it possible to use a For Loop to check each foo[i] against every property in an object?
Tom Hodgkinson
@LibLogic
Feb 20 2016 01:02
the test that come with the challenge give the correct answer'
Orestis Gklavas
@oglavas
Feb 20 2016 01:04
@LibLogic Your test for 3 returns 5, which is wrong
Jay
@jayleach
Feb 20 2016 01:04
I fixed the issue. Thank you @Michelle2016 and everyone else. :)
CamperBot
@camperbot
Feb 20 2016 01:04
jele233 sends brownie points to @michelle2016 :sparkles: :thumbsup: :sparkles:
CamperBot
@camperbot
Feb 20 2016 01:04
:star: 230 | @michelle2016 | http://www.freecodecamp.com/michelle2016
Tom Hodgkinson
@LibLogic
Feb 20 2016 01:04
@oglavas OMG thanks
CamperBot
@camperbot
Feb 20 2016 01:04
liblogic sends brownie points to @oglavas :sparkles: :thumbsup: :sparkles:
Tom Hodgkinson
@LibLogic
Feb 20 2016 01:04
lol
CamperBot
@camperbot
Feb 20 2016 01:04
:warning: liblogic already gave oglavas points
Tom Hodgkinson
@LibLogic
Feb 20 2016 01:05
@LibLogic No wait... 3 SHOULD return 5
2+3
Orestis Gklavas
@oglavas
Feb 20 2016 01:06
Oops....yes! 3.30 am... :(
2 is in fact a prime
Tom Hodgkinson
@LibLogic
Feb 20 2016 01:06
@oglavas No wait... 3 SHOULD return 5 since 2 + 3 is "5"
@LibLogic yea lol
Charles Chung
@chulmo
Feb 20 2016 01:07
@ThaleSelaht thanks for the link, but I'm not sure if that answers my question, see example below for a better explanation of my question:
 var obj = {
   1: [4, 5, 6],
   2: [2, 3, 4],
   3: [1, 2, 3],
   //etc....
 }

 for (var x = 0; x <= foo.length - 1; x++) {
   if (
     // look for foo[x] in every array in obj. 
     // If it exists in every array, 
     // then return that you found something
   ) {
     return "i found something in the object"
   }
 }
CamperBot
@camperbot
Feb 20 2016 01:07
chulmo sends brownie points to @thaleselaht :sparkles: :thumbsup: :sparkles:
:star: 157 | @thaleselaht | http://www.freecodecamp.com/thaleselaht
ThaleSelaht
@ThaleSelaht
Feb 20 2016 01:10
@chulmo which challenge is it?
@chulmo u need nested fors, figure the rest by urself
Charles Chung
@chulmo
Feb 20 2016 01:14
@ThaleSelaht cool
Orestis Gklavas
@oglavas
Feb 20 2016 01:16
@LibLogic What error do you get?
Tom Hodgkinson
@LibLogic
Feb 20 2016 01:17
@oglavas no error at all, it just doesnt pass
for some reason
someon suggested making it work for negative numbers
** account for
Orestis Gklavas
@oglavas
Feb 20 2016 01:21
@LibLogic : Well, I finally got my head unblocked and understood your code. Looks OK. Try writing a first line of //noprotect to turn off loop protection, since your code should be quite slow and probably gets cut by the loop protection system
Tom Hodgkinson
@LibLogic
Feb 20 2016 01:22
@oglavas hmm that didn't work......here is what I get
sumPrimes(10) should return a number.
sumPrimes(10) should return 17.
sumPrimes(977) should return 73156.
but that exactly what my code returns
for those examples
the first one passes the other 2 do not pass I get the red X. even thought my code returns those values ie: 17 and 73156, respectively
brb
James Good
@TajYemaj
Feb 20 2016 01:28
``
Hey, I have a question regarding this exercise. I was able to complete it, but I was just curious as to whether I wrote the code in the most efficient way.
Orestis Gklavas
@oglavas
Feb 20 2016 01:29
@LibLogic The only other thing I can think of, is that the tests do not work correctly with global variables
Tom Hodgkinson
@LibLogic
Feb 20 2016 01:30
I could try to rectify that and see if that works
good idea
I'll let you know
Orestis Gklavas
@oglavas
Feb 20 2016 01:31
@LibLogic I understand you are doing it for practice that way, right?
Tom Hodgkinson
@LibLogic
Feb 20 2016 01:32
yea, I wanted to do it with recursion
fist time I ever used it
plus I like reinventing the wheel....lol
Orestis Gklavas
@oglavas
Feb 20 2016 01:33
@LibLogic : If you'd like my opinion, this exercise is not the best target for recursion. Fibonacci numbers are much better, since there is something that recursion can work with in an understandable manner
Tom Hodgkinson
@LibLogic
Feb 20 2016 01:35
You are probably right, I still need to figure out when to use it or not....I know that it is SLOWER
Orestis Gklavas
@oglavas
Feb 20 2016 01:36
@LibLogic Either way, let me know what you came up with! I have to get to bed, before morning...Well, the standard use, is when you have a base case (e.g. f(0) = 1) and a repetitive process you can use to get to f(0) (i.e. f(2) = f(1)+f(0) )
Tom Hodgkinson
@LibLogic
Feb 20 2016 01:37
ok, thanks again for your help
Orestis Gklavas
@oglavas
Feb 20 2016 01:38
No problem...I wish my head was clearer... I could have done more...
Good night
Tom Hodgkinson
@LibLogic
Feb 20 2016 01:38
nite
Dusan Nikodijevic
@pika89
Feb 20 2016 01:52
wiki "find the longest word"
CamperBot
@camperbot
Feb 20 2016 01:52

:point_right: algorithm find the longest word in a string [wiki]

Explanation:

You have to go through each word and figure out which one is the longest and return not the word, but how many characters it has.

:pencil: read more about algorithm find the longest word in a string on the FCC Wiki

bitgrower
@bitgrower
Feb 20 2016 01:56
@chulmo -- do you still need help -- I was just looking at your example above, and will comment if you do ...
John Arevalo
@Jarevalo92
Feb 20 2016 02:07
can some1 help me with bonfire/algorithm "check for palindromes" ?
CamperBot
@camperbot
Feb 20 2016 02:07
type bonfire name to get some info on that bonfire. And check HelpBonfires chatroom
John Arevalo
@Jarevalo92
Feb 20 2016 02:08
function palindrome(str) {

  var rts = str.split('').reverse().join('');
  var fuck = rts.replace('_','').toLowerCase();

  if(str === rts)

     return true;

   else
     return false;
}



palindrome("race car");
i'm having trouble figuring out what to put in as my parameters for the .replace method
Harrison Amyotte
@amyottehm12
Feb 20 2016 02:08
var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};

var Bike = function() {

  // Only change code below this line.
  var gear = 4;

  this.getGear = function() {
    myBike.setGear();
  };

  this.setGear = function() {
    gear -= 1;
    return gear
  };

};

var myCar = new Car();

var myBike = new Bike();

So I'm on 'make object properties private' but i have no idea what it wants from me?

it has this for the checkmarks
myBike.getGear() should return 4 after calling myBike.setGear(4).
myBike.getGear() should return 3 after calling myBike.setGear(3).
myBike.getGear() should return 1 after calling myBike.setGear(1).
idk where im supposed to change the 4/3/1 part

John Arevalo
@Jarevalo92
Feb 20 2016 02:08
to delete spaces and push all of the letters in the array together
bitgrower
@bitgrower
Feb 20 2016 02:08
well, for one, you'll need to do .toLowerCase on both strings, I believe ...
John Arevalo
@Jarevalo92
Feb 20 2016 02:10
@bitgrower if I were to combine var fuck and var rts, what will I have to consider regarding the order of methods being implemented?
bitgrower
@bitgrower
Feb 20 2016 02:10
that's a rather broad question ... :)
Dusan Nikodijevic
@pika89
Feb 20 2016 02:10
wiki "title case a sentence"
CamperBot
@camperbot
Feb 20 2016 02:10

:point_right: algorithm title case a sentence [wiki]

Explanation:

We have to return a sentence with camel case. This means that the first letter will always be in uppercase and the rest lowercase.

:pencil: read more about algorithm title case a sentence on the FCC Wiki

bitgrower
@bitgrower
Feb 20 2016 02:11
for race car -- you need to delete the spaces...
bitgrower
@bitgrower
Feb 20 2016 02:16

Modify the Bike constructor to have a private property called gear and two public methods called getGear and setGear to get and set that value.

... @amyottehm12 -- they give you an example of a private variable in the Car constructor -- see how they do that, and then add one similarly to the Bike Constructor, named gear

...then you have to add 2 public methods -- again, just look at how they do that in the Car constructor, and do likewise ...
Harrison Amyotte
@amyottehm12
Feb 20 2016 02:18
i just don't get what i set my gear to at the start
and then it doesnt tell me what it wants to change the gears by? up? down? by what?
rybka02
@rybka02
Feb 20 2016 02:19

function lookUp(firstName, prop){

  var error = {

    noContact : "No such contact",
    noProp    : "No such property"

  };

  for (i=0; i<contacts.length;i++){
    if (contacts[i].firstName===firstName && contacts[i][prop]===undefined)
      return error.noProp;

    if (contacts[i].firstName===firstName && contacts[i][prop].hasOwnProperty)
      return contacts[i][prop];

  }

   return error.noContact;
}

lookUp("Akira", "address");
Is there better?
Harrison Amyotte
@amyottehm12
Feb 20 2016 02:20
i figured it out
myBike.getGear() should return 4 after calling myBike.setGear(4).
robynsmith
@robynsmith
Feb 20 2016 02:20

I’m on: Stand in Line

function queue(arr, item) {
  // Your code here
  var a = arr.shift();
  arr.push(item);
  console.log ("a: " + a);
  console.log("arr: " + arr);

  return a;  // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

When I manually run this through queue:

queue([], 1);

It returns an “undefined”.

Am I going about this wrong?

Harrison Amyotte
@amyottehm12
Feb 20 2016 02:21
made me think that the getGear() should call setGear in itself
which is not at all what they wanted
bitgrower
@bitgrower
Feb 20 2016 02:21
@amyottehm12 -- no increase or decrease ... just set a value -- don't think it's necessary to start the gear at any specific value ... pick on e... :)
Harrison Amyotte
@amyottehm12
Feb 20 2016 02:21
urgh they just worded that so dumb
why not just make it myBike.setGear(var) should set gear to var, and myBike.getGear() should simply return the gear
after they go on about not wanting you to be able to change the var except by increments
why bother making it private at this point
rybka02
@rybka02
Feb 20 2016 02:24
@robynsmith You'd be shifting an empty array
bitgrower
@bitgrower
Feb 20 2016 02:24
you mean about the car accelerating & decelerating ... ? Probably to get you used to picking out the salient information from what can be extraneous information ... not at all an uncommon event ...
robynsmith
@robynsmith
Feb 20 2016 02:24
@rybka02 THanks! That just made me figure it out
Got it to work
Dusan Nikodijevic
@pika89
Feb 20 2016 02:24
wiki "return largest numbers"
CamperBot
@camperbot
Feb 20 2016 02:24

:point_right: algorithm return largest numbers in arrays [wiki]

Explanation:

You will get an array that contains sub arrays of numbers and you need to return an array with the largest number from each of the sub arrays.

:pencil: read more about algorithm return largest numbers in arrays on the FCC Wiki

robynsmith
@robynsmith
Feb 20 2016 02:24
So yeah. Thank you @rybka02 !!!!
CamperBot
@camperbot
Feb 20 2016 02:24
robynsmith sends brownie points to @rybka02 :sparkles: :thumbsup: :sparkles:
bitgrower
@bitgrower
Feb 20 2016 02:24
YAY!!!! @robynsmith
CamperBot
@camperbot
Feb 20 2016 02:25
:star: 349 | @rybka02 | http://www.freecodecamp.com/rybka02
rybka02
@rybka02
Feb 20 2016 02:25
cool
Ikuyasu
@ikuyasu
Feb 20 2016 02:26
''''
function diff(arr1, arr2) {
var newArr = [];
// Same, same; but different.
arr1.filter(function(element) {
if (arr2.indexOf(element)===-1) {
newArr.push(element);
}
});
arr2.filter(function(element) {
if (arr1.indexOf(element)===-1) {
newArr.push(element);
}
});
return newArr;
}
"""
CamperBot
@camperbot
Feb 20 2016 02:26
:bulb: to format code use backticks! ``` more info
bitgrower
@bitgrower
Feb 20 2016 02:28
smart suggestion, @camperbot, thanks
CamperBot
@camperbot
Feb 20 2016 02:28
bitgrower sends brownie points to @camperbot :sparkles: :thumbsup: :sparkles:
Ikuyasu
@ikuyasu
Feb 20 2016 02:28
function diff(arr1, arr2) {
  var newArr = [];
  // Same, same; but different.
  arr1.filter(function(element) {
    if (arr2.indexOf(element)===-1) {
      newArr.push(element);
    }
  });
  arr2.filter(function(element) {
    if (arr1.indexOf(element)===-1) {
      newArr.push(element);
    }
  });
  return newArr;
}
From "Diff Two Arrays", the code above works but it is totally redundant to use .filter() twice. Is there any better way to do this?
CamperBot
@camperbot
Feb 20 2016 02:28
:star: 1216 | @camperbot | http://www.freecodecamp.com/camperbot
Franco Zapata
@Francozt01
Feb 20 2016 02:30
@ikuyasu use an else if statement?
bitgrower
@bitgrower
Feb 20 2016 02:30
you could make the function an externally callable function and call it twice w/diff parameters ... :)
rybka02
@rybka02
Feb 20 2016 02:31
^^^ I like bitgrower's idea.
bitgrower
@bitgrower
Feb 20 2016 02:32
if you're gonna use the same code more than once, make it external ... :)
folks get a little IIFE crazy around here, including me ...
rybka02
@rybka02
Feb 20 2016 02:38

function lookUp(firstName, prop){

  var error = {

    noContact : "No such contact",
    noProp    : "No such property"

  };

  for (i=0; i<contacts.length;i++){
    if (contacts[i].firstName===firstName && contacts[i][prop]===undefined)
      return error.noProp;

    if (contacts[i].firstName===firstName && contacts[i][prop].hasOwnProperty)
      return contacts[i][prop];

  }

   return error.noContact;
}

lookUp("Akira", "address");
Any suggestions here?
Ikuyasu
@ikuyasu
Feb 20 2016 02:39
function diff(arr1, arr2) {
  var newArr = [];
  // Same, same; but different.
  arr1.filter(function(element) {
    var index = arr2.indexOf(element);
    if (index===-1) {
      newArr.push(element);
    } else {
      arr2.concat(arr2.slice(0,index+1), arr2.slice(index+1, arr2.length));
    }
  });
  arr2.filter(function(element) {
    if (arr1.indexOf(element)===-1) {
      newArr.push(element);
    }
  });
  return newArr;
}
Okay, for "Diff Two Arrays", this is a bit of improvement. It removes the element from arr2 in the first .filter loop if it finds the same elements so that the second .filter loop will be shorter.
rybka02
@rybka02
Feb 20 2016 02:40
too messy for me
Ikuyasu
@ikuyasu
Feb 20 2016 02:40
Okay, I will try to make a global (external) function.
bitgrower
@bitgrower
Feb 20 2016 02:43
@ikuyasu -- actually, from a readability standpoint, I don't find it easier to read & understand ...
Ben
@ReductioAbsurdum
Feb 20 2016 02:44

How do I retrieve the second "list" when there are two "list" properties in this JSON?

// Setup
var myPlants = [
{
type: "flowers",
list: [
"rose",
"tulip",
"dandelion"
]
},
{
type: "trees",
list: [
"fir",
"pine",
"birch"
]
}
];

// Only change code below this line

var secondTree = myPlants.list1; // Change this line

rybka02
@rybka02
Feb 20 2016 02:45
myPlants[1].list
or myPlants[1]["list"]
Ben
@ReductioAbsurdum
Feb 20 2016 02:46
@rybka02 Thank you!
CamperBot
@camperbot
Feb 20 2016 02:46
reductioabsurdum sends brownie points to @rybka02 :sparkles: :thumbsup: :sparkles:
:star: 353 | @rybka02 | http://www.freecodecamp.com/rybka02
Ikuyasu
@ikuyasu
Feb 20 2016 02:50
function diff(arr1, arr2) {
  var newArr = [];
  // Same, same; but different.
  var myfun = function(arr, element) {
    var index = arr.indexOf(element);
    if (index===-1) 
      newArr.push(element); 
  };

  arr1.filter(function(element) {
    myfun(arr2, element);
  });

  arr2.filter(function(element) {
    myfun(arr1, element);
  });

  return newArr;
}
It may look a bit cleaner and it demonstrates my understanding of scope.
bitgrower
@bitgrower
Feb 20 2016 02:52
yup
Ikuyasu
@ikuyasu
Feb 20 2016 02:52
@bitgrower The improvement is done is "else" statement. The arr2 gets shorten for the second .filter loop. But I just posted the version with the external function.
bitgrower
@bitgrower
Feb 20 2016 02:52
yeah, i did someting like that when I did the symmetric difference challenge ...
really quiet around here ...
Ikuyasu
@ikuyasu
Feb 20 2016 02:53
I think using the external function and still run the efficient 2nd .filter loop is better.
But my external function version does not make .filter efficiently by removing the same value in the array.
bitgrower
@bitgrower
Feb 20 2016 02:55
the basic cs engineering approach is ... get it working, then worry about speeding it up ...
Ikuyasu
@ikuyasu
Feb 20 2016 02:55
In order to change arr2 in the first .filter(), I should not pass "arr" in the function.
Sure.
Now it's working so I am trying to make it better.
bitgrower
@bitgrower
Feb 20 2016 02:56
yeah ... you'll have another opportunity to play with the same concepts ...
bitgrower @bitgrower wonders if there's live coding going on, and everyone is over at twitch.tv
Ikuyasu
@ikuyasu
Feb 20 2016 02:57
Well, I guess I will just go on.
to the next challenge. It's good enough to find the better way to use an external function in this challenge.
bitgrower
@bitgrower
Feb 20 2016 03:00
yeah ... FCC doesn't show a lot of use of external functions ... maybe because it's, in general, "safer" (that is, less likely to result in name collisions) to use IIFE's ... but functions enclosed within a function should also take care of that issue... :)
Gabriel
@Zera99
Feb 20 2016 03:04
function where(arr, num) {
  var i = 0, index = -1;

  arr.sort(smallerThan);

  // I'll use length-1 so I can do i++ and not go over the boundary
  while(i < arr.length - 1 && index < 0){ 
    if(num >= arr[i] && num <= arr[i+1] ) {
      index = i+1;
    }
    i++;
  }
  if(index < 0) {
    index = arr.length;
  }
  return index;
}
function smallerThan(a, b) {
   // If it's negative, a will be considered smaller, by sort()
    return a - b; 
}

where([10, 20, 30, 40, 50], 30);
rybka02
@rybka02
Feb 20 2016 03:04
@ikuyasu Instead of using an anonymous function, create a separate external function.
Gabriel
@Zera99
Feb 20 2016 03:04
where([3, 10, 5], 3) should return 0. This is the only test It's failing.. halp D:
Jon Grant
@jong649
Feb 20 2016 03:05
Hey everyone, I'm on Symmetric Difference, and thought I could just flatten these arrays into one, then go from there....but I'm unsure of how to do that since the two arguments are separate arrays within parentheses, not arrays within arrays.....hopefully that made sense.
function sym(args) {
  return args;
}

sym([1, 2, 3], [5, 2, 1, 4]);
rybka02
@rybka02
Feb 20 2016 03:05
@jong649 Look up .reduce() javascript
Gabriel
@Zera99
Feb 20 2016 03:06
I guess I could just.. hardcode it
rybka02
@rybka02
Feb 20 2016 03:06
@Zera99 Make an if statement for when num == smallest number then return 0
Jon Grant
@jong649
Feb 20 2016 03:06
@rybka02 I was reading the article on Mozilla's help site, but I guess I've been away from JS for a while, doesn't make sense
rybka02
@rybka02
Feb 20 2016 03:06
@jong649 reduce is easy... it basically uses a, b
Gabriel
@Zera99
Feb 20 2016 03:07
Thanks @rybka02 * (Just to send the points)
CamperBot
@camperbot
Feb 20 2016 03:07
zera99 sends brownie points to @rybka02 :sparkles: :thumbsup: :sparkles:
:star: 354 | @rybka02 | http://www.freecodecamp.com/rybka02
Gabriel
@Zera99
Feb 20 2016 03:07
@rybka02 yeah that's what I did. Thanks
CamperBot
@camperbot
Feb 20 2016 03:07
zera99 sends brownie points to @rybka02 :sparkles: :thumbsup: :sparkles:
:warning: zera99 already gave rybka02 points
Gabriel
@Zera99
Feb 20 2016 03:07
Oh. Derp.
rybka02
@rybka02
Feb 20 2016 03:07
[1, 2, 3], [5, 2, 1, 4]
so in the above,... it takes [1, 2, 3] as a
and 5,2, 1, 4 as b
Jon Grant
@jong649
Feb 20 2016 03:08
@rybka0 I was trying that, but it was only seeing the [1,2,3] array and skipping the next one
I must have been doing something wrong then; I'll read more
Andrew Charlebois
@andrewchar
Feb 20 2016 03:08
looking for some advice for a recursive function that im working on
rybka02
@rybka02
Feb 20 2016 03:10
@jong649
 var flattened = [[0, 1], [2, 3], [4, 5]].reduce(function(a, b) {
  return a.concat(b);
}, []);
// flattened is [0, 1, 2, 3, 4, 5]
Jon Grant
@jong649
Feb 20 2016 03:10
@rybka02 I used that exact code, but it wasn't seeing the second array
sym([1, 2, 3], [5, 2, 1, 4]);
I was wondering if it's because the example args are 2 separate arrays, not multidimensional ones
rybka02
@rybka02
Feb 20 2016 03:11
it would be args.reduce(function(a, b) { ect.....
Jon Grant
@jong649
Feb 20 2016 03:11
@rybka02 yeah I had args.reduce(etc.
rybka02
@rybka02
Feb 20 2016 03:11
post code plz
which exercise is it?
Jon Grant
@jong649
Feb 20 2016 03:12
function sym(args) {
  var flattened = args.reduce(function(a, b) {
  return a.concat(b);
}, []);
}

sym([1, 2, 3], [5, 2, 1, 4]);
Symmetric Difference
rybka02
@rybka02
Feb 20 2016 03:13
are you returning flattened?
your sym function needs to return flattened
Jon Grant
@jong649
Feb 20 2016 03:13
function sym(args) {
  var flattened = args.reduce(function(a, b) {
  return flattened;
}, []);
}

sym([1, 2, 3], [5, 2, 1, 4]);
rybka02
@rybka02
Feb 20 2016 03:13
and why do you have []
no
not like that
which challenge is that
bitgrower
@bitgrower
Feb 20 2016 03:14
symmetric difference, @rybka02
Jon Grant
@jong649
Feb 20 2016 03:14
Symmetric Difference
bitgrower
@bitgrower
Feb 20 2016 03:15
I still need to study using .reduce ... I got it to work, but only with help ... :)
rybka02
@rybka02
Feb 20 2016 03:15
var flattened = [[0, 1], [2, 3], [4, 5]].reduce(function(a, b) {
  return a.concat(b);
}, []);
// flattened is [0, 1, 2, 3, 4, 5]
Jon Grant
@jong649
Feb 20 2016 03:15
Yeah, I've used it to flatten arrays within arrays, but this one is a little different
rybka02
@rybka02
Feb 20 2016 03:16
you still use a.concat(b)
but outside your reduce function you need to return flattened
well techncially its an anonymous function
Jon Grant
@jong649
Feb 20 2016 03:17
function sym(args) {
  var flattened = args.reduce(function(a, b) {
    return a.concat(b);
}, []);
  return flattened;
}

sym([1, 2, 3], [5, 2, 1, 4]);
still returning [1,2,3] only
rybka02
@rybka02
Feb 20 2016 03:18
bc it's flattened
you have a single array... but the challenge is more than just flattening it
i have to leave panera bread it's closed-- ill help when i get home
Jon Grant
@jong649
Feb 20 2016 03:19
yeah, a little more tricky than that haha
It's cool, thanks @rybka02
CamperBot
@camperbot
Feb 20 2016 03:19
jong649 sends brownie points to @rybka02 :sparkles: :thumbsup: :sparkles:
Jon Grant
@jong649
Feb 20 2016 03:19
I'm going to make some food
CamperBot
@camperbot
Feb 20 2016 03:19
:star: 355 | @rybka02 | http://www.freecodecamp.com/rybka02
bitgrower
@bitgrower
Feb 20 2016 03:23
@jong649 -- unfortunately, you can't do symmetric differences that way ... just fyi ... that was my first attack ... but in reading further on symmetric difference you'll see you could eliminate, say, the number 5 from the first 2, and then add it back in with the 3rd array ...
Meghana
@meghanasarikonda
Feb 20 2016 03:33
js
<function titleCase(str) {
  var newo=str.split(" ");
 var newWord=[];
  for (var i=0;i<newo.length;i++)
    {
      newWord=newo[i].substring(1).toLowerCase();
      newo[i]=newo[i][0].toUpperCase()+ newWord;
    }
newo=newo.join(" ");
return newo;
}




  titleCase("I'm a little tea pot");>
can anyone explain me this code
bitgrower
@bitgrower
Feb 20 2016 03:35
does it work ?
Meghana
@meghanasarikonda
Feb 20 2016 03:35
@bitgrower yeah
bitgrower
@bitgrower
Feb 20 2016 03:36
which part are you having the most trouble understanding ?
Meghana
@meghanasarikonda
Feb 20 2016 03:37
@bitgrower actually the for loop part
@bitgrower what is substring doing
bitgrower
@bitgrower
Feb 20 2016 03:37
newo contains all the words in the argument passed
did you look up substring in Mozilla Developer Network ?
Olivia Legge
@livmaria7891
Feb 20 2016 03:41
@meghanasarikonda .substring() is just taking a subsection of the string at newo[i], starting at 1… basically it’s taking every letter except the first letter of a word to convert to lower case.
Meghana
@meghanasarikonda
Feb 20 2016 03:44
@livmaria7891 actually strings are immutable right ,then how can we assign individual parts
bitgrower
@bitgrower
Feb 20 2016 03:44
you can affect the string and the mutation of the string is put into the new variable ... newWord

so ... newo[i] = "somestring";

the line of code takes everything from o to the end and makes it lower case ... and assigns it to newWord

Olivia Legge
@livmaria7891
Feb 20 2016 03:47
@meghanasarikonda Hmm good question. I can’t answer that as an expert, but I know that .substring() is one of the methods for a string that is built into javascript that allows us isolate a part of the string.
bitgrower
@bitgrower
Feb 20 2016 03:48
it doesn't affect the string that newo[i] is pointing at ... but it does take the contents, copies it, modifies it according to the functions called, and assigns it to newWord ...
the functions being ...
substring
toLowerCase
Olivia Legge
@livmaria7891
Feb 20 2016 03:49
@bitgrower Yes, good point, the original string isn’t modified..just the substring.
bitgrower
@bitgrower
Feb 20 2016 03:52
:shipit:
Meghana
@meghanasarikonda
Feb 20 2016 03:57
@bitgrower
js
<newo[i]=newo[i][0].toUpperCase()+ newWord;>
Preston Moore
@FrOyxx
Feb 20 2016 03:57
For the section JSON APIs and AJAX, it seems I'm just copying and pasting the code supplied each time. What are the key concepts we should be taking from these exercises?
Meghana
@meghanasarikonda
Feb 20 2016 03:57
then what about this statemant
@bitgrower
we cant make one word in a string to capital know
bitgrower
@bitgrower
Feb 20 2016 03:58
LOL .. good question @FrOyxx -- I need to go review that ... I suspect some of the lessons there are useful when going on to the challenges formerly known as ziplines ...
so @meghanasarikonda -- you remember that you can concatenate strings with the "+" character, right ?
Preston Moore
@FrOyxx
Feb 20 2016 03:59
@bitgrower Ok. Some of the concepts seem a little involved but you aren't asked to do much. I think I might be missing out.
bitgrower
@bitgrower
Feb 20 2016 03:59
so .. we know we have newWord is equal to omestring ...
Meghana
@meghanasarikonda
Feb 20 2016 04:00
@bitgrower yeah
bitgrower
@bitgrower
Feb 20 2016 04:00
now we are grabbing the FIRST character of somestring, uppercasing it, and catenating it with omestring ...
we are doing the equivalent of what we did with omestring, that is, since we are just wanting to look at one character, we can index into the string and grab it ... at location 0 ... -- then we uppercase it ...
Andrew Charlebois
@andrewchar
Feb 20 2016 04:01
if you were trying to find a certain letter in a string and count how many times it presents itself. would using a for loop to find it be a good solution?
or would regex
Meghana
@meghanasarikonda
Feb 20 2016 04:02
@bitgrower okay we can pick individual characters
right
bitgrower
@bitgrower
Feb 20 2016 04:02
yes -- you can index into the string, just like you can index into an array ... :)
Andrew Charlebois
@andrewchar
Feb 20 2016 04:03
and take into account that the time it takes the function is irrelevant
bitgrower
@bitgrower
Feb 20 2016 04:03
@andrewchar -- I would probably use an IIFE in a replace statement
Andrew Charlebois
@andrewchar
Feb 20 2016 04:04
@bitgrower brb while i read what that even is lol
bitgrower
@bitgrower
Feb 20 2016 04:04
look under string functions at Mozilla Developer Network, then look for replace ... :)
if I were lazy, I'd probably just iterate thru the string, @andrewchar
Andrew Charlebois
@andrewchar
Feb 20 2016 04:07
so it runs soon as its called
is the general idea of it
bitgrower
@bitgrower
Feb 20 2016 04:07
ah yes ... know any jQuery ?
Andrew Charlebois
@andrewchar
Feb 20 2016 04:07
yeh but im sticking to spaghetti
lol
im specifically sticking to it to learn fundamentals
maybe telling you what im doing first will clear it up. i have a task which is ""Write a function countBs that takes a string as its only argument and returns a number that indicates how many uppercase “B” characters are in the string.""
bitgrower
@bitgrower
Feb 20 2016 04:08
with js -- IIFE's are pretty standard ...
very common ...
eh, just use a for loop ... unless you want to get super fancy ... looks like a beginning assignment ... so, it depends on how far you want to go ...
Andrew Charlebois
@andrewchar
Feb 20 2016 04:09
could i show you my code i have so far
bitgrower
@bitgrower
Feb 20 2016 04:09
I dunno if a regex would return you the number of hits ...
Meghana
@meghanasarikonda
Feb 20 2016 04:09
@bitgrower okay thank u
CamperBot
@camperbot
Feb 20 2016 04:09
meghanasarikonda sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
Andrew Charlebois
@andrewchar
Feb 20 2016 04:09
its probly a mess, i cant get it to work yet
CamperBot
@camperbot
Feb 20 2016 04:09
:star: 586 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 20 2016 04:09
is a bit of sunlight of understanding seepig in @meghanasarikonda ?
Andrew Charlebois
@andrewchar
Feb 20 2016 04:10
@bitgrower yeah im reading a book and its one of the assignments
heres my code so far.
function countBs(str) {
var howManyBs = 0;
  for (var i = 0; i < str.length; i++ )
  if (str == "B")
    howManyBs += 1;

  return howManyBs;
}

console.log(countBs("BBC"));
// → 2
bitgrower
@bitgrower
Feb 20 2016 04:10
I don't expect it necessarily is completely clear @meghanasarikonda -- but if you think it adds just a bit, that is probably the little piece you need to make it all work
@andrewchar -- you need to know how to address a specific character in a string ...
Hemedi
@Hemedi
Feb 20 2016 04:11
help No repeats please
CamperBot
@camperbot
Feb 20 2016 04:11

:point_right: algorithm no repeats please [wiki]

Problem Explanation:

  • This task requires us to look at each possible permutation of a string. This is best done using a recursion function. Being able to build a function which collects all permutations of a string is a common interview question, so there is no shortage of tutorials out there on how to do this, in many different code languages.
  • This task can still be daunting even after watching a tutorial. You will want to send each new use of the function 3 inputs: 1. a new string (or character array) that is being built, 2. a position in your new string that's going to be filled next, and 3. an idea of what characters (more specifically positions) from the original string have yet to be used. The pseudo code will look something like this:

    ```
    var str = ???;
    perm(current position in original string, what's been used in original string, current string build thus far){
    if(current string is finished) {
    print current string;
    }else{
    for(var i = 0; i < str.length; i++) {

    if(str[i] has not been used) {
      put str[i] into the current position;
      mark str[i] as used
      perm(current position in original string, what's been used in original string, current string build thus far)
      unmark str[i] as used because another branch in the tree for i + 1 will still likely use it;
    }

    }
    }
    }
    :pencil: read more about algorithm no repeats please on the FCC Wiki

Andrew Charlebois
@andrewchar
Feb 20 2016 04:12
@Hemedi lol you just fixed my problem
@Hemedi you made it show that bit of code in the help, it made me notice what i did wrong in my code
@bitgrower got it working.. replaced () with []
Hemedi
@Hemedi
Feb 20 2016 04:13
I'm also stuck on this LOL
Andrew Charlebois
@andrewchar
Feb 20 2016 04:13
@Hemedi im actually doing assignments out of a javascript book im reading
bitgrower
@bitgrower
Feb 20 2016 04:14
LOL ... which js book @andrewchar ?
Andrew Charlebois
@andrewchar
Feb 20 2016 04:14
@bitgrower eloquentjavascript
Hemedi
@Hemedi
Feb 20 2016 04:14
Isn't that online as well
??
Andrew Charlebois
@andrewchar
Feb 20 2016 04:14
@bitgrower also reading the you dont know JS series slowly as i get more JS experience
yeah its a free book
bitgrower
@bitgrower
Feb 20 2016 04:15

k -- there's also a reference to an annotated version you can find here ...

help javascript resources

Andrew Charlebois
@andrewchar
Feb 20 2016 04:15
i can link you to free books if you want
bitgrower
@bitgrower
Feb 20 2016 04:15
bah
bitgrower @bitgrower kicks @camperbot
Hemedi
@Hemedi
Feb 20 2016 04:15
that would be useful
bitgrower
@bitgrower
Feb 20 2016 04:15
help js resources
bitgrower
@bitgrower
Feb 20 2016 04:15
sheesh ...
3rd one down, under tutorials ...
Hemedi
@Hemedi
Feb 20 2016 04:15
@bitgrower thanks
CamperBot
@camperbot
Feb 20 2016 04:15
hemedi sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 587 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 20 2016 04:16
@Hemedi -- no repeats has me a bit perplexed as well ...
Hemedi
@Hemedi
Feb 20 2016 04:16
I'm stumped as well
I copied the camper bot pseudo code and am trying to work with it
bitgrower
@bitgrower
Feb 20 2016 04:17
I mean ... clearly the a's are treated as different ..
Andrew Charlebois
@andrewchar
Feb 20 2016 04:18
@bitgrower thanks a lot!
CamperBot
@camperbot
Feb 20 2016 04:18
andrewchar sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
Hemedi
@Hemedi
Feb 20 2016 04:18
Yeah
CamperBot
@camperbot
Feb 20 2016 04:18
:star: 588 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 20 2016 04:18
yw @andrewchar
one of the last 3 of the advanced algo problems I need to do ... :)
and it seems like it should be the easiest of the 3 !!!
Hemedi
@Hemedi
Feb 20 2016 04:19
haha
I still have five more to go
bitgrower
@bitgrower
Feb 20 2016 04:19
not sure if I've looked at the pseudocode ... I did look at the permuations ...
Hemedi
@Hemedi
Feb 20 2016 04:19
Taking a break now, maybe things will be clearer when I come back
Andrew Charlebois
@andrewchar
Feb 20 2016 04:19
i look at the intermediate algorithms
tried the first one for a bit
and realized maybe i dont know that much
i still have 2 front end projects before i am actually at the point of doing them but i figured i would look at one and yeah
bitgrower
@bitgrower
Feb 20 2016 04:20
yeah, i was trying to make an associate array out of the exact change one ... but it wasn't working as I expected ... and friendly dates ... I'm sure there's an easier way to do it ... but MAN that's a lot of conditions to go thru ... I think there are 6 different types of date formats to return ...
Andrew Charlebois
@andrewchar
Feb 20 2016 04:21
i actually misread what the question was, did the whole thing and then realized i didnt do what it ACTUALLY asked me to do
bitgrower
@bitgrower
Feb 20 2016 04:21
yeah, they changed the order around ... before, the front end projects came after a bit of js ... and the js was a bit addictive ... so ... kinda kept going forward with the algos ... but now I'm getting interested/excited about doing the front ends ...
if I'm lucky, maybe I'll get it all done & have my fe cert by the end of March ... :)
@andrewchar -- not an uncommon problem ...
my advice for FCC algo challenges ...
  1. be sure to read waht's wanted
  2. be sure to understand what's to be provided & what's to be returned (seeing the testcases may help)
  3. be sure to read the helpful hints
  4. be sure you understand the arguments you are being handed, and use them...
  5. be sure you are returning the answer
then ... also look for typos ... use console.log, use pythontutor.com/javascript.html to help ...
Andrew Charlebois
@andrewchar
Feb 20 2016 04:26
The Annotated Version is an in-progress project?
bitgrower
@bitgrower
Feb 20 2016 04:26
shrug dunno ... is that what it says ?
rybka02
@rybka02
Feb 20 2016 04:27
@jong649 You still there?
bitgrower
@bitgrower
Feb 20 2016 04:27
haven't seem them in a while, @rybka02
rybka02
@rybka02
Feb 20 2016 04:28
When you get back... use :
args = Array.prototype.slice.call(arguments, 0);
and it will work
bitgrower
@bitgrower
Feb 20 2016 04:28
which challenge were they working on?
Andrew Charlebois
@andrewchar
Feb 20 2016 04:28
just glanced over it, i see part 1 up to chapter 8
bitgrower
@bitgrower
Feb 20 2016 04:29
ahh ... okay ... I haven't looked at it in depth .. just had seen the ref in the FCC docs ...
btw -- when you are doing equals, you nearly always want to use ===
rybka02
@rybka02
Feb 20 2016 04:29
and replace you reduce statement with:
var flattened = args.reduce(function(a, b) { 
        return a.concat(b); 
    }); 
return flattened;
bitgrower
@bitgrower
Feb 20 2016 04:30
that way js will not do implicit type conversions and cause hard-to-find bugs
Andrew Charlebois
@andrewchar
Feb 20 2016 04:30
@bitgrower i usually do but in this casei knew i was just checking for a couple of letters. like 5 letter strings. didnt think it mattered
bitgrower
@bitgrower
Feb 20 2016 04:30
good practice, though ... :)
Andrew Charlebois
@andrewchar
Feb 20 2016 04:31
@bitgrower i think its because i was worried about caps or non caps
bitgrower
@bitgrower
Feb 20 2016 04:31
don't understand, @andrewchar
rybka02
@rybka02
Feb 20 2016 04:31
anyone stuck?
Andrew Charlebois
@andrewchar
Feb 20 2016 04:36
@bitgrower i thought it would make a difference since some letters that i was picking out of the string were CAPS and some were not, but it didn't make a difference
bitgrower
@bitgrower
Feb 20 2016 04:36
@rybka02 -- did you get Profile Lookup to work okay ?
@andrewchar nah ... === is actually more restrictive, anyway ...
btw -- just saw your reference to you don't know js -- yeah, that's another popular one around here...abbreviated YDKJS, I think ... :)
Andrew Charlebois
@andrewchar
Feb 20 2016 04:40
@bitgrower yes, im on the second book now
@bitgrower apparently it ramps up quickly
rybka02
@rybka02
Feb 20 2016 04:40
@bit yes
bitgrower
@bitgrower
Feb 20 2016 04:41
a number of us like the udemy course mentioned in the FCC wiki on js resources ...
that was my first foray into non-FCC js resources ...
rybka02
@rybka02
Feb 20 2016 04:41
Mine works-- i just wanted to know if anyone had upgrade suggestions
function lookUp(firstName, prop){

  var error = {

    noContact : "No such contact",
    noProp    : "No such property"

  };

  for (i=0; i<contacts.length;i++){
    if (contacts[i].firstName===firstName && contacts[i][prop]===undefined)
      return error.noProp;

    if (contacts[i].firstName===firstName && contacts[i][prop].hasOwnProperty)
      return contacts[i][prop];

  }

   return error.noContact;
}

lookUp("Akira", "address");
Andrew Charlebois
@andrewchar
Feb 20 2016 04:42
@bitgrower i almost payed for stuff from that site
bitgrower
@bitgrower
Feb 20 2016 04:42
no... in fact, that's kinda cool ...
Andrew Charlebois
@andrewchar
Feb 20 2016 04:42
resource javascript
bitgrower
@bitgrower
Feb 20 2016 04:43
I love the error object ...
rybka02
@rybka02
Feb 20 2016 04:43
ty
bitgrower
@bitgrower
Feb 20 2016 04:43
@andrewchar -- which site?
Andrew Charlebois
@andrewchar
Feb 20 2016 04:43
udemy
js resource
help js resource
Andrew Charlebois
@andrewchar
Feb 20 2016 04:44
you talking about this "Udemy - Javascript Understanding the Weird Parts (first 3.5 hrs)" ?
bitgrower
@bitgrower
Feb 20 2016 04:44
you managed to get the whole course for free ?
Andrew Charlebois
@andrewchar
Feb 20 2016 04:44
no no
bitgrower
@bitgrower
Feb 20 2016 04:44
or just the 3.5 hours ...
Andrew Charlebois
@andrewchar
Feb 20 2016 04:44
when i was very new to coding
still had no path or site
i almost payed for their service
bitgrower @bitgrower watched the first 3.5 hours on YT ... then liked it enough to go buy his udemy course (for $10)
bitgrower
@bitgrower
Feb 20 2016 04:45
paid for whose service ? sorry, still confused ...
Andrew Charlebois
@andrewchar
Feb 20 2016 04:45
we are talking about udemy right
lol
bitgrower
@bitgrower
Feb 20 2016 04:45
yeah ...
Andrew Charlebois
@andrewchar
Feb 20 2016 04:45
payed udemy
courses
bitgrower
@bitgrower
Feb 20 2016 04:46
so you didn't pay for OTHER udemy courses ?
Andrew Charlebois
@andrewchar
Feb 20 2016 04:46
i did not pay for any. when i was just getting into learning to code (before i knew about fcc) i was going to pay for a bunch of their courses
i had no idea i could get so much for free until i searched around the web
bitgrower
@bitgrower
Feb 20 2016 04:48
oh yeah, very true ... big time ... and there are ever present $10 udemy coupons if you get the desire to sign up for any of their courses ...
Andrew Charlebois
@andrewchar
Feb 20 2016 04:51
now i wanna watch this udemy vid lol
read books, watch vids, read articles, get some fcc projects done.. not enough time in a day :P
@bitgrower how long you been coding
bitgrower
@bitgrower
Feb 20 2016 04:53
long time, @andrewchar
before there was a web...
Andrew Charlebois
@andrewchar
Feb 20 2016 04:56
oh lol
TheKingIsHere
@TheKingIsHere
Feb 20 2016 04:58
When working on challenge for accessing nested objects in JSON, I am not understanding how to access the contents without hard coding without bracket notation to retrieve the info
myStorage.gloveBoxContents=[0]
bitgrower
@bitgrower
Feb 20 2016 04:58
first programs I ever wrote I had to create punch cards ... :) And we had to load the operating system in with a card reader :)
@TheKingIsHere -- can you post your code ...
TheKingIsHere
@TheKingIsHere
Feb 20 2016 04:59
// Setup
var myStorage = {
  "car": {
    "inside": {
      "glove box": "maps",
      "passenger seat": "crumbs"
     },
    "outside": {
      "trunk": "jack"
    }
  }
};

// Only change code below this line

myStorage.gloveBoxContents=[0]; // Change this line
bitgrower
@bitgrower
Feb 20 2016 04:59
but coding with javascript -- since January ...
Andrew Charlebois
@andrewchar
Feb 20 2016 04:59
gotcha
ive been gong for almost 3 months now
bitgrower
@bitgrower
Feb 20 2016 05:00
awesome, keep it up ...
Andrew Charlebois
@andrewchar
Feb 20 2016 05:00
got layed off for the winter and decided to give this a real go
8-10 hours a day coding
bitgrower
@bitgrower
Feb 20 2016 05:00
good!!!!
@TheKingIsHere -- which challenge is it ?
TheKingIsHere
@TheKingIsHere
Feb 20 2016 05:01
accessing nested objects in json
bitgrower
@bitgrower
Feb 20 2016 05:01
k ... let me go look and see what I did, and I'll be able to answer your question better .. :)
bitgrower @bitgrower needs to review those challenges ...
Andrew Charlebois
@andrewchar
Feb 20 2016 05:02
you need to target your glove box key
to get the value of it
TheKingIsHere
@TheKingIsHere
Feb 20 2016 05:02
@andrewchar how many languages how are u working on?
@bitgrower no prob
Andrew Charlebois
@andrewchar
Feb 20 2016 05:02
focusing on javascript
i guess im following FCC's curriculum
and just picking up books about it
bitgrower
@bitgrower
Feb 20 2016 05:03
to answer your question, @TheKingIsHere -- yes ... you need to hard code the property you're looking for ...
unlike arrays, there's not as simple of a way to find the properties belonging to an object by just using something like a numeric index ...
as you follow along, you'll see how to access them in other ways ...
Andrew Charlebois
@andrewchar
Feb 20 2016 05:05
i believe target with dot notation and bracket is the key there if i remember correctly
bitgrower
@bitgrower
Feb 20 2016 05:05
pretty much, the first challenges ... until you get to the algo challenges ... use the example code in the challenge description ...
so .... if they are using explicit values, that's what they are doing to guide you into what you need to do ...

for instance .. in their example they use

ourStorage.cabinet["top drawer"].folder2;

Andrew Charlebois
@andrewchar
Feb 20 2016 05:07
@andrewchar purple?
why no purple text! lol
bitgrower
@bitgrower
Feb 20 2016 05:08
hahahahaha ...
it's a trick ...
Andrew Charlebois
@andrewchar
Feb 20 2016 05:08
lol
bitgrower
@bitgrower
Feb 20 2016 05:08

just like this is

Andrew Charlebois
@andrewchar
Feb 20 2016 05:08
<strong>merp</strong>
MERP
bitgrower
@bitgrower
Feb 20 2016 05:08
hahahahahahaha ...
you want to see what people are doing .. go over to the right and click on the dots that show up to the right of the time, use quote ... and you can see what they are doing
bitgrower @bitgrower that's how I learned the last trick ...
bitgrower
@bitgrower
Feb 20 2016 05:09
the purple text comes from far-too-many-hours in irc chat rooms ...
Andrew Charlebois
@andrewchar
Feb 20 2016 05:10
oh i see now
well
ive been at this for like 12 hours
its time to get off and rest lol
rest my brain
good chatting, Gnight
bitgrower
@bitgrower
Feb 20 2016 05:18
indeed ... keep up the great work, @andrewchar
Cam
@CamMakoJ
Feb 20 2016 05:29

function destroyer(arr) {
var arg = arguments.length;
var argz = arguments[0];
var i = 0;
var argi = arguments[i];

function cats(value) {
return value !== argi;
}
for (i = 1; i < arg; i++) {
var dogs = argz.filter(cats);
console.log(dogs);
}

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

hi all sorry i psted that first
TheKingIsHere
@TheKingIsHere
Feb 20 2016 05:37
@bitgrower I am still having trouble with exercise for accessing nested objects in json
DJ
@qualitymanifest
Feb 20 2016 05:38
@CamMakoJ arguments[0] is arr. so you can get rid of your first 4 lines in the destroyer function. you'll then need to be able to use the rest of arguments, so you'll need to put all additional arguments into an array you can use. then you can filter arr based on whether or not the additional arguments are present in arr
bitgrower
@bitgrower
Feb 20 2016 05:39
k, @TheKingIsHere -- what do you have now ?
TheKingIsHere
@TheKingIsHere
Feb 20 2016 05:39
Not sure where I went wrong this time
// Setup
var myStorage = {
  "car": {
    "inside": {
      "glove box": "maps",
      "passenger seat": "crumbs"
     },
    "outside": {
      "trunk": "jack"
    }
  }
};

// Only change code below this line

myStorage.car["inside"].glovebox ;// Change this line
bitgrower
@bitgrower
Feb 20 2016 05:40
use a dot notation for inside, @TheKingIsHere ... follow as precisely the example they provide in the description ...
NainaPS
@Navyya
Feb 20 2016 05:41
heya guys it had been too long that i had been here
i need a help for
bitgrower
@bitgrower
Feb 20 2016 05:42
wb @Navyya ...
NainaPS
@Navyya
Feb 20 2016 05:42
Slasher Flick
i just need hint what to do ....
bitgrower
@bitgrower
Feb 20 2016 05:42
post whatcha got ... :)
NainaPS
@Navyya
Feb 20 2016 05:42
n i will try if not
bitgrower
@bitgrower
Feb 20 2016 05:42
I seem to recall slasher flick as being fun ... :)
NainaPS
@Navyya
Feb 20 2016 05:43
so @bitgrower what should be done
Otman Bouchari
@obouchari
Feb 20 2016 05:43
@TheKingIsHere Also glovebox is not the same as “glove box"
budimanfix
@budimanfix
Feb 20 2016 05:45

hello what I missing here guys : ar Bike = function(){
var getGear = 4;
this.setGear = function (getGear,metod){
getGear += metod;

};
this.getGear = function (setGear){
setGear -= 3;
};
this.setGear = function (setGear){
return setGear;
}

TheKingIsHere
@TheKingIsHere
Feb 20 2016 05:46
would I use bracket notation to around that element
bitgrower
@bitgrower
Feb 20 2016 05:47
@Navyya -- did you post your code & I missed it ?
hello @obouchari , @budimanfix
Otman Bouchari
@obouchari
Feb 20 2016 05:47
@TheKingIsHere Yep
bitgrower
@bitgrower
Feb 20 2016 05:48
@budimanfix -- setGear is used to assign a value coming in from the parameter setGear ...
I would also not name my arguments the same as my public functions, it gets too confusing ...
Otman Bouchari
@obouchari
Feb 20 2016 05:48
Hey @bitgrower How are things going?
bitgrower
@bitgrower
Feb 20 2016 05:49
not too badly -- down to 3 adv algo challenges ... starting to see what sorts of cool thing I can do on the frontend challenges ... :)
& you ?
NainaPS
@Navyya
Feb 20 2016 05:50
@bitgrower

function slasher(arr, howMany) {
// it doesn't always pay to be first
var k=[];
k.splice(arr[0],1);
return k.splice(arr,1);
}

slasher([1, 2, 3], 2);

bitgrower
@bitgrower
Feb 20 2016 05:50
@budimanfix -- it certainly makes talking about the different pieces clearly more difficult ... because if I refer to setGear .. it's not clear whether I'm talking about ... :)
NainaPS
@Navyya
Feb 20 2016 05:50
but it gives me [] null
bitgrower
@bitgrower
Feb 20 2016 05:50
help slasher
CamperBot
@camperbot
Feb 20 2016 05:50

:point_right: algorithm slasher flick [wiki]

Problem Explanation:

Return the remaining elements of an array after chopping off n elements from the head.

For example: slasher([1, 2, 3], 2); must return [3]

:pencil: read more about algorithm slasher flick on the FCC Wiki

Otman Bouchari
@obouchari
Feb 20 2016 05:51
Cool! I’m still working on some Intermediate Challanges to move to Adv one
I was taking other courses in other places
bitgrower
@bitgrower
Feb 20 2016 05:52
where are you referencing the value howMany, Navyya ? and while you're at it, can you format your code as to @camperbot's sweet instructions ...
explain format
CamperBot
@camperbot
Feb 20 2016 05:52

:point_right: code formatting [wiki]

Inline code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

Code Block

```js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

``` ⇦ Type 3 backticks, then press [enter ⏎]

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

:pencil: read more about code formatting on the FCC Wiki

bitgrower
@bitgrower
Feb 20 2016 05:52
yeah, I got sort of addicted to the js challenges ...
Otman Bouchari
@obouchari
Feb 20 2016 05:53
Me too
bitgrower
@bitgrower
Feb 20 2016 05:53
function slasher(arr, howMany) {
  // it doesn't always pay to be first
  var k=[];
 k.splice(arr[0],1);
  return k.splice(arr,1);
}

slasher([1, 2, 3], 2);
@navvya's code, formatted
Otman Bouchari
@obouchari
Feb 20 2016 05:54
You feel like you got to beat it
bitgrower
@bitgrower
Feb 20 2016 05:54
really ...
Otman Bouchari
@obouchari
Feb 20 2016 05:58
Everytime I finish a challange I still think there is a better way
budimanfix
@budimanfix
Feb 20 2016 05:58
@bitgrower I not find this one on wiki
bitgrower
@bitgrower
Feb 20 2016 05:59
I think it has "private" in the name ...
@budimanfix
oh ... you mean, for help ?
budimanfix
@budimanfix
Feb 20 2016 06:00
@bitgrower for example to following
bitgrower
@bitgrower
Feb 20 2016 06:03
hang on ...
the example is provided in the code, with the Car Constructor ... .
we're talking about the same one, right ?
if not, which one are we talking about ? :)
TheKingIsHere
@TheKingIsHere
Feb 20 2016 06:10
@obouchari I have added the var to define it as 'maps' and still have no success, am I heading in the right direction
// Setup
var myStorage = {
  "car": {
    "inside": {
      "glove box": "maps",
      "passenger seat": "crumbs"
     },
    "outside": {
      "trunk": "jack"
    }
  }
};

// Only change code below this line

var gloveBoxContents = "maps"; // Change this line
myStorage.car.inside["glove box"].gloveBoxContents;
bitgrower
@bitgrower
Feb 20 2016 06:12
@TheKingIsHere -- you can stop at ["glove box"] ...
glove box is the property, and you are using it as an "index" to return the value of the property ...
Otman Bouchari
@obouchari
Feb 20 2016 06:14
@TheKingIsHere “maps” is the value you want to get
TheKingIsHere
@TheKingIsHere
Feb 20 2016 06:15
@bitgrower that was exactly what I was thinking but when I run test I only receive 1/2 with me stopping at ['glove box']
Otman Bouchari
@obouchari
Feb 20 2016 06:15
@TheKingIsHere So this myStorage.car.inside["glove box”] will return that value
TheKingIsHere
@TheKingIsHere
Feb 20 2016 06:19
@obouchari That is what I currently have and it does return 'maps' but isn't that do to me declaring the variable
bitgrower
@bitgrower
Feb 20 2016 06:20
which challenge is this again, @TheKingIsHere ?
TheKingIsHere
@TheKingIsHere
Feb 20 2016 06:20
accessing nested objects in json
V Arun Kumar
@arunvkumr
Feb 20 2016 06:21
@TheKingIsHere it returns maps because you declared glove contents as maps. use dot operator to find the value maps in storage.
Otman Bouchari
@obouchari
Feb 20 2016 06:21
@TheKingIsHere Yes you have to assign what you getting from that nested object to gloveBoxContents
bitgrower
@bitgrower
Feb 20 2016 06:22
yeah, @arunkumrv -- I think he's got that part now ... :)
@TheKingIsHere -- pay attention to what @obouchari said ...
E
@efhjones
Feb 20 2016 06:24
Hi @bitgrower :wave: Would you mind giving me a pointer if you have a sec? I'm working on caesars cipher, and I'm just trying to do the first part, which is (I assume) converting the chars to numbers. For some reason it's not pushing the numbers to my new array. I've tried a few other things and came to a stop at this one...
function rot13(str) { // LBH QVQ VG!

 for (i=0; i<str.length; i++){
  var n = str.charCodeAt(0+i);
var numbersArray = [];
 numbersArray.push(n);
}return n;
}
bitgrower
@bitgrower
Feb 20 2016 06:26
can you explain, line by line, what you are trying to do ?
E
@efhjones
Feb 20 2016 06:26
sure, just a sec
bitgrower
@bitgrower
Feb 20 2016 06:27
I think your definition of n in the return statement will have n as being out of scope, hence, undefined ...
you also should use var i in your for loop def
E
@efhjones
Feb 20 2016 06:29
It does, it's returning a number still through, what makes it out of scope? Would I have to declare n before the function? Hope these comments clear it up, let me know if it still doesn't make sense:
function rot13(str) { // LBH QVQ VG!

 for (i=0; i<str.length; i++){//loop through the whole string

  var n = str.charCodeAt(0+i); //Get the charCode at this index in the str and assign it to n
var numbersArray = [];
 numbersArray.push(n);// push code that's now sitting in 'n' to numbersArray
}return n;
}
bitgrower
@bitgrower
Feb 20 2016 06:30
and you are constantly re-defining numbersArray as the empty array ...
E
@efhjones
Feb 20 2016 06:30
oooh
yup. :laughing:
I think I'm only getting to the first index in the string? I keep getting 83 which = s
Otman Bouchari
@obouchari
Feb 20 2016 06:33
@bitgrower @efhjones n will not be out of scope but its recomanded to declare your vars at top inside the function
bitgrower
@bitgrower
Feb 20 2016 06:33
I"m not entirely crystal clear on the js scoping rules ... so my bad on n ... but stylistically it might be a bit more clear if you defined n outside the loop ... but that's jmo ... so take it for what it is worth ...
E
@efhjones
Feb 20 2016 06:33
Oh! Hang on, I think I might have got something...
bitgrower
@bitgrower
Feb 20 2016 06:33
thanks @obouchari
CamperBot
@camperbot
Feb 20 2016 06:33
bitgrower sends brownie points to @obouchari :sparkles: :thumbsup: :sparkles:
:star: 356 | @obouchari | http://www.freecodecamp.com/obouchari
E
@efhjones
Feb 20 2016 06:35
Got my string of numbers, yay! Thanks @bitgrower @obouchari I'll see if I can get to the next step :laughing: thanks for your help
CamperBot
@camperbot
Feb 20 2016 06:35
efhjones sends brownie points to @bitgrower and @obouchari :sparkles: :thumbsup: :sparkles:
:star: 590 | @bitgrower | http://www.freecodecamp.com/bitgrower
:star: 357 | @obouchari | http://www.freecodecamp.com/obouchari
bitgrower
@bitgrower
Feb 20 2016 06:35
awesome ... :)
Otman Bouchari
@obouchari
Feb 20 2016 06:35
well done @efhjones
E
@efhjones
Feb 20 2016 06:35
Oh, what did changing i to var i do?
bitgrower
@bitgrower
Feb 20 2016 06:36
@efhjones -- also check your code out at http://pythontutor.com/javascript.html
it keeps it from being a global variable ...
Otman Bouchari
@obouchari
Feb 20 2016 06:36
@bitgrower that was agreat tool I use it to understand execution process of my code everytime now
bitgrower
@bitgrower
Feb 20 2016 06:37
when you look at the syntax coloring ... if you see you are using any variables that are colored white and you don't want them to be global (99% of the time) ... put var in front of them ... :)
E
@efhjones
Feb 20 2016 06:37
Ah ok thanks!
Otman Bouchari
@obouchari
Feb 20 2016 06:38
@efhjones Also using strict mode will prevent you from such habit anyway :p
bitgrower
@bitgrower
Feb 20 2016 06:38
yeah, I love that ... not sure how I discovered it ... if someone posted it in here, I wished I would remember, but I don't even know if that's the case ... maybe I found it on stack exchange ... I just don't remember ...
anyway -- I discovered it around the time I was hitting my head on Seek & Destroy ... and didn't understand the difference between named arguments and the arguments array ... :) ..
Otman Bouchari
@obouchari
Feb 20 2016 06:39
I see
MikeBeers
@MikeBeers
Feb 20 2016 06:40
hey bitgrower
turning this in
bitgrower
@bitgrower
Feb 20 2016 06:40
hey @MikeBeers -- how ya doing ... ?
awesome ... congrats !!!!!
MikeBeers
@MikeBeers
Feb 20 2016 06:42
thanks for your help on this project
Travis Boss
@travisboss
Feb 20 2016 06:42
On the access multi dimensional array where you input myArray[0], [0] with a series of numbers above. It had me equal 8 which I figured out but I do not understand it exactly. What is finding what to get 8?
bitgrower
@bitgrower
Feb 20 2016 06:43
yw ... do you use a select set of colors, so you don't end up using a color which makes your headline hard to read ?
@travisboss -- can you post your code ?
you want to add something slick,, add some animation to your quote boxes ... :)
Travis Boss
@travisboss
Feb 20 2016 06:44

'''javascript
// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray2;
'''

CamperBot
@camperbot
Feb 20 2016 06:44
:bulb: to format code use backticks! ``` more info
bitgrower
@bitgrower
Feb 20 2016 06:44
have 'em fade in, fade out ... move around ... etc ...
MikeBeers
@MikeBeers
Feb 20 2016 06:44
I guess I could make it black
bitgrower
@bitgrower
Feb 20 2016 06:45
actually, the color you have seems to work well, I think it works better than black would, tbh ...
Travis Boss
@travisboss
Feb 20 2016 06:45

'''js
// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray2;
'''

CamperBot
@camperbot
Feb 20 2016 06:45
:bulb: to format code use backticks! ``` more info
bitgrower
@bitgrower
Feb 20 2016 06:45
^^^ @travisboss -- pay attention to @camperbot's hints -- you can edit your post
backticks -- upper left hand of your keyboard ...
MikeBeers
@MikeBeers
Feb 20 2016 06:45
ok. I will try and add some animation to the quotes
Travis Boss
@travisboss
Feb 20 2016 06:45
sorry i am a fool
bitgrower
@bitgrower
Feb 20 2016 06:46
LOL ... no you're not ...
trust me, you're not ...
Travis Boss
@travisboss
Feb 20 2016 06:46
I understand now
bitgrower
@bitgrower
Feb 20 2016 06:46
error codes are your friends ... even if they seem as obscure as hell sometimes ...
Travis Boss
@travisboss
Feb 20 2016 06:47
// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[2][1];
there it is
bitgrower
@bitgrower
Feb 20 2016 06:47
usually when you figure them out ... you have a facepalm -- and say "ooooohhhhh... so THAT's what that means...."
Travis Boss
@travisboss
Feb 20 2016 06:47
i figured out and got it to equal 8 I just did not understand what I was actually doing
bitgrower
@bitgrower
Feb 20 2016 06:47
okay ... so, you understand simple array addressing, right ?
hello ?
Travis Boss
@travisboss
Feb 20 2016 06:48
somewhat. when i chose my array i just am unsure what I was selecting was 2 the second array and was 1 the first array?
bitgrower
@bitgrower
Feb 20 2016 06:49
so ... an array ... just a simple, 1 dimensional array ... you know what it means when you say something like array[5], right ?
2 is the THIRD array -- don't forget 0-based indexing ...
1 is, correspondingly the SECOND element --
Travis Boss
@travisboss
Feb 20 2016 06:50
ok so i think i get it
bitgrower
@bitgrower
Feb 20 2016 06:50
other than that, I think your understanding is correct -- you're just off by one ... :)
redeyesblackdragon
@redeyesblackdragon
Feb 20 2016 06:50

function myTest(val) {
var answer = "";
// Only change code below this line

// Only change code above this line
return answer;
}

// Change this value to test
myTest(1);

Travis Boss
@travisboss
Feb 20 2016 06:50
so when i chose 2 since it starts from 0 it chose the "3rd" array then it chooses the number in the array with the second number
bitgrower
@bitgrower
Feb 20 2016 06:50
what would you like us to do @redeyesblackdragon
yes @travisboss
redeyesblackdragon
@redeyesblackdragon
Feb 20 2016 06:51

Instructions

Write a switch statement to set answer for the following conditions:
"a" - "apple"
"b" - "bird"
"c" - "cat"
default - "stuff"

Travis Boss
@travisboss
Feb 20 2016 06:51
@bitgrower thanks
CamperBot
@camperbot
Feb 20 2016 06:51
travisboss sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 591 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 20 2016 06:51
so have you tried anything, @redeyesblackdragon ?
Travis Boss
@travisboss
Feb 20 2016 06:51
i would just hate to skate thru and not really understand
redeyesblackdragon
@redeyesblackdragon
Feb 20 2016 06:51
i tried alreayd but had to delete my code so i can copy and paste the original
bitgrower
@bitgrower
Feb 20 2016 06:51
yw @travisboss -- it's easy once you know it ... just remember programmers are weird and start numbering at 0
good thing to do @travisboss
@redeyesblackdragon -- yes please, that way we can see where your thinking is going off into the weeds ...
redeyesblackdragon
@redeyesblackdragon
Feb 20 2016 06:52
its "Adding a default option in Switch statements" challenge
bitgrower
@bitgrower
Feb 20 2016 06:53
so, this means you've done a previous challenge where you dealt with a switch statement, yes ?
redeyesblackdragon
@redeyesblackdragon
Feb 20 2016 06:54
thanks for the insult man
bitgrower
@bitgrower
Feb 20 2016 06:55
no, I am not trying to be insulting ... I'm trying to find where you're at ...
right now you have no switch statement ...
so it's a reasonable question ...
redeyesblackdragon
@redeyesblackdragon
Feb 20 2016 06:55
oh okay that what it was ill check back in if it doesnt work
bitgrower
@bitgrower
Feb 20 2016 06:56
well, it's a switch statement to which you add a default ... :)
Lê Thành
@Luvata
Feb 20 2016 06:56
I don't know what's the mistake at my code : check for Palindrome .
Why "0_0 (: /-\ :) 0-0" always return false even other all are correct?
var str2 = str.toLowerCase().replace(/\W/g, '');
  var str3 = str2.split('').reverse().join('');
  if (str3===str2) {return true ;}
  else {return false;}
bitgrower
@bitgrower
Feb 20 2016 06:57
some people will find it trivially easy, others will find it very hard ... and those who understand it easily don't understand why people have trouble ... :)
@Luvata -- you need to remove all the non-alpha characters out of the string ...
and \W may not be doing exactly what you expect -- go research exactly what \W does ...
Lê Thành
@Luvata
Feb 20 2016 06:59
@bitgrower tks, I think my problem is from this replace too ~~! I will find the replace method again .
CamperBot
@camperbot
Feb 20 2016 06:59
luvata sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 592 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 20 2016 07:00
cool ... happy coding, @Luvata
redeyesblackdragon
@redeyesblackdragon
Feb 20 2016 07:05
ok this is what i put but got it wrong

function myTest(val) {
var answer = "";
// Only change code below this line
switch (val) {
case 1:
"apple" - "a";
break;
case 2:
"bird" - "b";
break;
case 3:
"cat" - "c";
break;
...
default:
default - "stuff";
}

// Only change code above this line
return answer;
}

// Change this value to test
myTest(1);

Lê Thành
@Luvata
Feb 20 2016 07:07
@bitgrower
I found a method : /[^a-z0-9]/g and it works, but is there other methods that help me to remove non-alphanumeric characters ?
TheKingIsHere
@TheKingIsHere
Feb 20 2016 07:07
@bitgrower This has not worked well for me momentarily but when shouldn't I call the newly named variable?
 var gloveBoxContents = "maps"; // Change this line
 myStorage.car.inside["glove box"] = gloveBoxContents;
bitgrower
@bitgrower
Feb 20 2016 07:08
swap the last statement, @TheKingIsHere

@Luvata -- not sure ... you can find lots and lots and lots about regexes here ...

help regexes

wiki regexes
CamperBot
@camperbot
Feb 20 2016 07:09
no wiki entry for: regexes
bitgrower
@bitgrower
Feb 20 2016 07:09
hmmm ...
help regex
CamperBot
@camperbot
Feb 20 2016 07:09

:point_right: js regex resources [wiki]

Links to useful RegEx resources.

See also: :clipboard: Tutorials | :syringe: Testing | :soccer: Games | :newspaper: Blogs | :package: Software

:pencil: read more about js regex resources on the FCC Wiki

Davinw
@Davinw
Feb 20 2016 07:10
@TheKingIsHere to elaborate what bitgrower is saying, when you are using an assignment statement(variable = value), you always put the variable you are changing on the left side on the equals sign :)
bitgrower
@bitgrower
Feb 20 2016 07:12
exactly -- you are s to set gloveBoxContents to some value, the value you just accessed from the object ...
redeyesblackdragon
@redeyesblackdragon
Feb 20 2016 07:12
yo?
bitgrower
@bitgrower
Feb 20 2016 07:13
@redeyesblackdragon -- the legitimate values you are being given are "a", "b", "c" ... so you have to set up the case statements to look for them specifically ...
TheKingIsHere
@TheKingIsHere
Feb 20 2016 07:13
@bitgrower thanks for working with me
CamperBot
@camperbot
Feb 20 2016 07:13
thekingishere sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 593 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 20 2016 07:13
you're most welcome @TheKingIsHere
TheKingIsHere
@TheKingIsHere
Feb 20 2016 07:13
@Davinw thanks for clarifying
CamperBot
@camperbot
Feb 20 2016 07:13
thekingishere sends brownie points to @davinw :sparkles: :thumbsup: :sparkles:
:star: 93 | @davinw | http://www.freecodecamp.com/davinw
Davinw
@Davinw
Feb 20 2016 07:13
@TheKingIsHere Yw!
redeyesblackdragon
@redeyesblackdragon
Feb 20 2016 07:14
and how to you suppose i do that?
bitgrower
@bitgrower
Feb 20 2016 07:14
well ... you do it like this ...
switch (val) {
   case "a":
      answer = "apple";
      break;
and so on ..
you have to test for the values the instructions tell you are being sent to the function ...
and then, if the value you get doesn't match any of those values ( "a", "b", "c") ... then you have a default statement ... which looks pretty much like what they show in the instructions for the challenge ...
redeyesblackdragon
@redeyesblackdragon
Feb 20 2016 07:17
youre a life saver man
bitgrower
@bitgrower
Feb 20 2016 07:19

ah... be your own lifesaver ... lots and lots and lots of code examples around the web ... and tutorials ... google "how to create a switch statement" ... for more examples than the challenge gives you ...

...so that's how you would find your answers for that challenge ... but you can do the same for any challenge ... go search in google for the topic ... you'll probably come across stackexchange which is FULL of advice, examples & more ...

redeyesblackdragon
@redeyesblackdragon
Feb 20 2016 07:20
point taken
Brian
@sludge256
Feb 20 2016 07:20
It's much for fun to bother @bitgrower though
bitgrower
@bitgrower
Feb 20 2016 07:21
ha ... I work for brownie points ... LOL ...
Brian
@sludge256
Feb 20 2016 07:22
Well brownies are going like...hotcakes.
bitgrower
@bitgrower
Feb 20 2016 07:23
thing is ... it will expand your capabilities as a programmer much faster, as well ... the challenges teach ONE example ... go out and see how else the constructs are used, it can inspire your imagination ... you end up going ... oh wow, i can do THIS with THAT ???
hah ~! @sludge256
redeyesblackdragon
@redeyesblackdragon
Feb 20 2016 07:26
its seems that you use stackexchange for the expansion of your mediocre phrases as well lmao
Om Prakash
@iamprakashom
Feb 20 2016 07:26
@Davinw thank you for clarifying :+1:
CamperBot
@camperbot
Feb 20 2016 07:26
iamprakashom sends brownie points to @davinw :sparkles: :thumbsup: :sparkles:
:star: 98 | @davinw | http://www.freecodecamp.com/davinw
Davinw
@Davinw
Feb 20 2016 07:26
@iamprakashom You are welcome! Were you able to get it to work?
bitgrower
@bitgrower
Feb 20 2016 07:26
LOL @redeyesblackdragon -- not really sure what you mean by that ... but whatever ...
budimanfix
@budimanfix
Feb 20 2016 07:27

Hello guys what I missing here : var array = [1, 12, 21, 2];

// Only change code below this line.

array = array.sort();

bitgrower
@bitgrower
Feb 20 2016 07:28
@budimanfix -- did you read the array.sort page ?
budimanfix
@budimanfix
Feb 20 2016 07:30
@bitgrower only left this task: You should have sorted the array from largest to smallest.
Om Prakash
@iamprakashom
Feb 20 2016 07:30
@Davinw yeah :smile: :sparkles:
Davinw
@Davinw
Feb 20 2016 07:30
@iamprakashom Great!
bitgrower
@bitgrower
Feb 20 2016 07:31
@budimanfix -- would it help if I told you the exact solution can be found on the array.prototype.sort page in MDN ? ;)
Manan Kalra
@manankalra
Feb 20 2016 07:42
http://www.freecodecamp.com/challenges/chunky-monkey
I'm stuck on Chunkey-Monkey!
Can anyone help?
function chunk(arr, size) {
  var groups = Math.floor(arr.length/size); 
  var remaining = arr.length%size;
  var total;
  if(remaining<size && arr.length!=size && size!=1){
    total = groups + 1;
  }
  else{
    total = groups + remaining;
  }
  for(var i=0;i<total;i++){
    arr.slice(i, i+2);
  }


  return arr;
}

chunk(["a", "b", "c", "d"], 2);
I don't know what I'm trying to do!
bitgrower
@bitgrower
Feb 20 2016 07:45
@mananKalra -- can you try talking it out ... ?
what are you looking for ... in your own words ?
Manan Kalra
@manankalra
Feb 20 2016 07:46
I was storing the number of sub-arrays that are to be made in the variable total.
Nikolajs Korolkovs
@NickEU
Feb 20 2016 07:46
@mananKalra slice() doesn't change the array it's being called on, it returns a new array as a result, so you're gonna wanna store that somewhere... also, if you do slice(9, 15 ) for example on an array that has a length of 12 it'll just extract till the end of an array, so you don't need you check and you don't have to worry about the remainder... as far as your for loop logic, you have a few problems there
arr.slice(i, i+2); here (i+2)doesn't make sense, where did it come from? :) also, increment at the end of the iteration i++ doesn't make any sense, you'll want to increase it by size after each loop iteration, so you move along the array and keep slicing the chunks of required size and returning them into your new array that u're gonna return in the end
Manan Kalra
@manankalra
Feb 20 2016 07:48
@NickEU i+=size ?
Nikolajs Korolkovs
@NickEU
Feb 20 2016 07:48
;) why don't you try it out and see what happens ;) do you know how to use a debugger?
Manan Kalra
@manankalra
Feb 20 2016 07:49
Debugger, no!
I'll try @NickEU
Nikolajs Korolkovs
@NickEU
Feb 20 2016 07:49
@mananKalra wait
@mananKalra http://watchandcode.com/courses/eloquent-javascript-the-annotated-version/lectures/292229 you can also just use console.log in some online JS environment if you don't like the way chrome console looks/work, like this one: https://repl.it/languages/javascript
learning how to debug your code is the first thing you should learn before trying to solve algorithmic challenges, it's a huge problem with FCC that has to be fixed asap - a series of waypoints before the algo challenges with some exercises would go a long way, this problem basically makes people rage and give up :) when in reality debugging is simple, powerful and allows you to find and correct mistakes you wouldn't find otherwise
i'm not even talking watchlist/breakpoints, a simple console.log on each loop iteration will go a long way in helping you understand how your code works and why it doesn't work the way you want it to work
Manan Kalra
@manankalra
Feb 20 2016 07:53
I'll go through it @NickEU
Thank you so much!
CamperBot
@camperbot
Feb 20 2016 07:53
manankalra sends brownie points to @nickeu :sparkles: :thumbsup: :sparkles:
:star: 378 | @nickeu | http://www.freecodecamp.com/nickeu
bitgrower
@bitgrower
Feb 20 2016 07:53
Agree that knowing how to debug is super important, @NickEU ... people try to figure out the algo challenges without even knowing how to use console.log
Davinw
@Davinw
Feb 20 2016 07:55
@NickEU Hey I hadn't heard of this annotated version of Eloquent JavaScript, looks great! That book jumps off a cliff in difficulty so this sounds very helpful
Nikolajs Korolkovs
@NickEU
Feb 20 2016 07:56
@Davinw it's unfinished, but it does a decent job of expanding on some concepts and giving some useful side info
@bitgrower yup
Davinw
@Davinw
Feb 20 2016 07:57
@NickEU Well for free I can't complain too much :)
Nikolajs Korolkovs
@NickEU
Feb 20 2016 07:58
@Davinw exactly, i'm elated to grab any info i can get ;) so i couldn't agree more :P
the problem is, most of the "free" resources suck or are outdated... this guy actually knows what he's talking about and has been around the block :) so that helps @Davinw I would actually argue that bad advice is worse than no advice ;) And bad info is worse than no info at all
Davinw
@Davinw
Feb 20 2016 08:01
@NickEU All true! Especially that bad advice/info being worse than none. There's a couple of good free ES6 resources I've found. If you are looking at functional Javascript, Javascript Allonge was updated to ES6. Although I find his examples to be overly abstract sometimes
bitgrower
@bitgrower
Feb 20 2016 08:02
hey -- fwiw ... the annotated eloquent js IS mentioned in FCC js resources
help js resources
Nikolajs Korolkovs
@NickEU
Feb 20 2016 08:02
@Davinw don't worry about ES6 so much... it doesn't introduce anything groundbreaking ;) Some nice new features, but the core of the language stays the same
Davinw
@Davinw
Feb 20 2016 08:06
@NickEU Well avoiding having to use IIFEs and closures to the same extant in ES6 is very nice, I've always found them to be counter-intuitive
bitgrower
@bitgrower
Feb 20 2016 08:09
eh @davinw -- where are you seeing that as aspects of ES6 ? :)
Davinw
@Davinw
Feb 20 2016 08:09
@bitgrower Also thanks for pointing that it's listed in the resources!
CamperBot
@camperbot
Feb 20 2016 08:09
davinw sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 594 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 20 2016 08:10
yeah, I am a big fan of the udemy course referenced ...
Nikolajs Korolkovs
@NickEU
Feb 20 2016 08:10
um.. i'm pretty sure u'll still want to use self-invoking functions anyway, or some managers to avoid naming conflicts when u're using a bunch of JS libraries and stuff in your app.... I don't see let keyword changing that xD But maybe i'm unaware of all the awesome features.. And closures is one of the most powerful features of the language, why would you not want to use it? ;)
Davinw
@Davinw
Feb 20 2016 08:10
@bitgrower block scoping with "let" essentially, instead of function level scoping with var. It was the function level scoping of var that introduced the need for most closures and IIFEs
well sure, appropriate module namespacing for small-medium+ scale stuff is always necessary
@NickEU I just don't like the way closures look on the page tbh :)
Nikolajs Korolkovs
@NickEU
Feb 20 2016 08:13
meh, enjoy your babel )
Davinw
@Davinw
Feb 20 2016 08:14
@NickEU this blog post has a good example for let simplifying things re: closures : http://tech.namshi.com/blog/2014/10/19/welcome-es6-javascript-is-not-fancy-anymore/
Nikolajs Korolkovs
@NickEU
Feb 20 2016 08:19
the example on closures is actually terrible, apparently the guy never heard of the keyword this lol
Manan Kalra
@manankalra
Feb 20 2016 08:19
@NickEU Still in doubt!
function chunk(arr, size) {
  var length = arr.length;
  for(var i=0;i<arr.length-size;i+=size){
    arr.push(arr.slice(i, i+size));
  }  
  for(var j=0;j<length;j++){
    arr.shift();
  }
  return arr;
  }

chunk(["a", "b", "c", "d", "e"], 2);
Nikolajs Korolkovs
@NickEU
Feb 20 2016 08:19
@mananKalra use a different array variable to store your result
and push the subarrays from arr into that new variable in your for loop
bitgrower
@bitgrower
Feb 20 2016 08:20
@mananKalra -- describe the type of data structure you need to return ...
Nikolajs Korolkovs
@NickEU
Feb 20 2016 08:20
@mananKalra also this doesn't look right i<arr.length-size
bitgrower
@bitgrower
Feb 20 2016 08:20
well .. @nickEu kinda hit the point I was trying to make ... but it's still worth doing ...
What kind of data structure do you need to return ... ?
Manan Kalra
@manankalra
Feb 20 2016 08:21
@bitgrower an array
bitgrower
@bitgrower
Feb 20 2016 08:21
an array of ... ?
Nikolajs Korolkovs
@NickEU
Feb 20 2016 08:21
@mananKalra your original end condition with total made more sense ;)
Manan Kalra
@manankalra
Feb 20 2016 08:21
@NickEU Why do I need a temperary var?
Nikolajs Korolkovs
@NickEU
Feb 20 2016 08:22
ugh
because you don't want to change the array that's being passed as a parameter, because you're working with that array in your loop
Joseph
@revisualize
Feb 20 2016 08:23
@mananKalra Why are you doing the arr.shift?
@mananKalra Why are you doing everything to the array instead of creating a new variable?
Manan Kalra
@manankalra
Feb 20 2016 08:24
@revisualize After pushing the sliced pieces, the original elements that were there before are still present, so I'm popping them from front upto the length of the original array that was passed as the argument.
Joseph
@revisualize
Feb 20 2016 08:24
I just did this:
  for (var i = 0, dblArr = []; i < arr.length; i) {
    dblArr.push(arr.slice(i, i+=size));
  }
  return dblArr;
Nikolajs Korolkovs
@NickEU
Feb 20 2016 08:24
@revisualize and spoiling the solution helps him how?
Joseph
@revisualize
Feb 20 2016 08:25
But, they are making it harder than it needs to be.
They already have ALL(most) all of that code in there.
bitgrower
@bitgrower
Feb 20 2016 08:25
well ... yeah, but it helps them to remember if they come up with the answer themselves ....
Manan Kalra
@manankalra
Feb 20 2016 08:25
@bitgrower @NickEU I'll retry!
Different than @revisualize
:D
bitgrower
@bitgrower
Feb 20 2016 08:26
people remember what they discover on their own even better than what they are taught ... :)
Joseph
@revisualize
Feb 20 2016 08:27
meh... I don't need to discover what it feels like to have my face dragged across concrete to be taught that it sucks.. really really bad.
So, yeah.
bitgrower
@bitgrower
Feb 20 2016 08:29

you aren't doing them a favor by handing people a solution ... if that were the case, that's what FCC would be doing ...

...sometimes it takes wandering around a lot to get the insight ... and learning HOW to get insights is one of those important software skills people really don't talk about too much ...

Joseph
@revisualize
Feb 20 2016 08:29
It does.
Davinw
@Davinw
Feb 20 2016 08:30
@revisualize that's certainly true - but I think @bitgrower 's point is that for learning, if they haven't really grasped the "what" and the "why" of the task, then knowing the "how" won't be very helpful
The answer.
I understand your point. Trust me I do.
Nikolajs Korolkovs
@NickEU
Feb 20 2016 08:31
no you don't
bitgrower
@bitgrower
Feb 20 2016 08:32
yeah, and what do all those solutions on the FCC wiki say -- they ask, remind, cajole people to first try really, really hard to come up with the solution on their own, first ...
Joseph
@revisualize
Feb 20 2016 08:32

The performance of writing everything to an array.

  var length = arr.length;
  for(var i=0;     i <       arr.length-size;        i+=size){
    arr.push(arr.slice(i, i+size));
  }

(Which mind you by increasing the size of the array every time you iterate across the array means that the array constantly grows.)

The performance sucks to write everything to the existing array then just shift off the stuff makes things really really slow.
Aleksander Gębicki
@Takumar
Feb 20 2016 08:35
@budimanfix I think that you have completed this already, but I said to you earlier to: "@budimanfix you can say that you haven't found your contact after you check every record in the contacts, that means after your loop completes!"
That means that you should put return "No such contact" after your loop, it looks like you haven't done it.
Joseph
@revisualize
Feb 20 2016 08:37
what happens if I do this:
var array = [1, 2, 3]
for (var i = 0; i < array.length; i++) {
    array.push(i);
    console.log(i);
}
How about this. You let me know when that code finishes. I'll sit here and hold my breath.
Still holding my breath.
bitgrower
@bitgrower
Feb 20 2016 08:38
don't know who you are talking to, or about, @revisualize
Joseph
@revisualize
Feb 20 2016 08:41
Sorry I did a > instead of the code < ... Fixed!
That's better. It now runs FOREVER.
Timofey Votyakov
@tvotyakov
Feb 20 2016 08:42
@bitgrower it looks like @revisualize want to prove something to somebody.
Joseph
@revisualize
Feb 20 2016 08:42
@mananKalra Sorry for giving you the answer before realizing that your code was an infinite loop.
Dulshani Gunawardhana
@dshgna
Feb 20 2016 08:42
Hi
Need review for my solution for smallest common multiple. It works, but I was wondering if I could make it more elegant.
function smallestCommons(arr) {
  var scm = 1;
  var factors = {};
  var min = Math.min(arr[0], arr[1]);
  var max = Math.max(arr[0], arr[1]);

  function getFactorCount(num, div){
    var count = 0; 
    while( num%div === 0 ){
      num = num/div;
      count++;
    }
    if (factors.hasOwnProperty(""+div) && count>factors[""+div]){
      factors[""+div] = count;
    } else if (!factors.hasOwnProperty(""+div) && count>0) { 
      factors[""+div] = count; 
    }
    return num;
  } 

  function getPrimeFactors(number) {  
    var n = getFactorCount(number, 2);
    for(var d=3; d<=Math.sqrt(number); d++){
      n = getFactorCount(n, d);
    }
    //prime number
    if(n===number && n!==1){
      factors[number] = 1; 
    }
  }

  for(var i=min; i<=max; i++){
    getPrimeFactors(i);
  }

  for (var divisor in factors) {
    scm *= Math.pow(parseInt(divisor), factors[divisor]);
  }

  return scm;
}
sigursiguros
@sigursiguros
Feb 20 2016 08:45
HI guys, I'm working on the steamroller function. Can you let me know what's wrong with my code? ot
it's returning an empty array
function steamroller(arr) {
  // I'm a steamroller, baby

  var flattened = [];

  for (var i=0; i<arr.length; i++){
    if (Array.isArray(arr[i])) {
      flattened = arr.reduce(function(a, b) {
      return a.concat(b);
      }, []);

    } 
   return flattened;
  }
}

steamroller([1, [2], [3, [[4]]]]);
bitgrower
@bitgrower
Feb 20 2016 08:47
@dshgna -- I would recommend documenting your code so people could more easily see what you are trying to do ... :)
you can explain your thinking, if you like ... :)
Timofey Votyakov
@tvotyakov
Feb 20 2016 08:51
@sigursiguros it looks like you need to move your return flattened; outside of for-loop.
bitgrower
@bitgrower
Feb 20 2016 08:51
@sigursiguros -- what is the very first element you test with Array.isArray ?
as well as what @tvotyakov said ...
you need an else for your if Array.isArray ...
sigursiguros
@sigursiguros
Feb 20 2016 08:55
to check if it's an array
if i use only the reduce function it returns the array with 4 itself in an array like [1,2,3,[[4]]];
looks like it's still the case with my for loop though...
Dulshani Gunawardhana
@dshgna
Feb 20 2016 08:56
@bitgrower here you go
function smallestCommons(arr) {
  var scm = 1;
  // associative array for a prime factor and the max amount of times it occurs
  var factors = {}; 
  var min = Math.min(arr[0], arr[1]);
  var max = Math.max(arr[0], arr[1]);

  //get the number of times that a prime factor is repeated in division
  function getFactorCount(num, div){
    var count = 0; 
    while( num%div === 0 ){
      num = num/div;
      count++;
    }
    if (factors.hasOwnProperty(""+div) && count>factors[""+div]){
      factors[""+div] = count;
    } else if (!factors.hasOwnProperty(""+div) && count>0) { 
      factors[""+div] = count; 
    }
    return num;
  } 


  // get all prime factors for a number
  function getPrimeFactors(number) {  
    //first check divisibility by first prime: two
    var n = getFactorCount(number, 2);
    //then for all odd numbers
    for(var d=3; d<=Math.sqrt(number); d +=2){
      n = getFactorCount(n, d);
    }
    //in the case that the number is itself a prime number
    if(n===number && n!==1){
      factors[number] = 1; 
    }
  }


  // for each number between min and max, get the prime factors
  for(var i=min; i<=max; i++){
    getPrimeFactors(i);
  }

  // get smallest common divisor by multiplying the largest amount of times a prime factor occurs
  for (var divisor in factors) {
    scm *= Math.pow(parseInt(divisor), factors[divisor]);
  }

  return scm;
}
bitgrower
@bitgrower
Feb 20 2016 08:56
LOL ... I didn't ask you what it's doing, I'm asking what is it going to do with the first thing it looks at? @sigursiguros
sigursiguros
@sigursiguros
Feb 20 2016 09:00
true false?
bitgrower
@bitgrower
Feb 20 2016 09:00
what is arr[0] ?
sigursiguros
@sigursiguros
Feb 20 2016 09:00
I don't understand why the reduce function itself would return [1,2,3,[[4]]]
first element of the array
bitgrower
@bitgrower
Feb 20 2016 09:00
can't help you with reduce ...
but what IS it ? is it an array? a number? a subarray ?
sigursiguros
@sigursiguros
Feb 20 2016 09:01
number
bitgrower
@bitgrower
Feb 20 2016 09:02
good -- so, what is it going to do on that test ?

if (Array.isArray(number) { ...

what does it do ?

where does the code go ...
sigursiguros
@sigursiguros
Feb 20 2016 09:03
it returns false?
so I have to push the number to another array you meaN?
bitgrower
@bitgrower
Feb 20 2016 09:03
sounds likely .. :) ... so what does it do next ...

so I have to push the number to another array you meaN?

...well there is that ... but I also want you to see what your code is doing ... to be able to read your own code and see why ...

sigursiguros
@sigursiguros
Feb 20 2016 09:04
if it returns false then it goes to the next element in the array
bitgrower
@bitgrower
Feb 20 2016 09:05
...not the way your code is written ...
sigursiguros
@sigursiguros
Feb 20 2016 09:05
why?
if I put return outside of the for loop
it should loop through all elements in the array
bitgrower
@bitgrower
Feb 20 2016 09:06
and it doesn't do anything if the item is a number ...
sigursiguros
@sigursiguros
Feb 20 2016 09:07
which is fine right? I just wanna flatten the arrays
the problem is the last four is looped inside another array
so I'd need another layer of loop?
bitgrower
@bitgrower
Feb 20 2016 09:07
you need an else ...
....imnsho ...
and when you get down to the number, push it into your answer array ...
then each of your numbers is exactly that, just an element in an array ...
sigursiguros
@sigursiguros
Feb 20 2016 09:09
does using the reduce function get me down tot he number?
bitgrower
@bitgrower
Feb 20 2016 09:11

@dshgna ... documentation about the parts is good, but what your approach to solving the problem is not completely obvious to me ... without really reading your code hard ...

I can tell you how I solved mine ... but I'm not quite sure how it fits with what you've done ...

...though I tend to like socratic teaching, so I would rather ask you questions so you'll gain insight :)

but it's late here ... so brain power isn't full force ...
@sigursiguros -- as I said above, i can't help you with reduce ...
sigursiguros
@sigursiguros
Feb 20 2016 09:13
Thanks @bitgrower
CamperBot
@camperbot
Feb 20 2016 09:13
sigursiguros sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 595 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 20 2016 09:14
yw @sigursiguros
Dulshani Gunawardhana
@dshgna
Feb 20 2016 09:18
@bitgrower lets start the Q&A then :D
bitgrower
@bitgrower
Feb 20 2016 09:19
okay ... tell me your basic plan, in words, for solving this challenge ... no code ... just tell me your approach ... :)
Pedro Abel Díaz Sánchez
@coderHook
Feb 20 2016 09:19

Hello, I am having problems passing this waypoint Get JSON with the jQuery getJSON Method bascially, its not displaying what it should, but I can pass to the next waypoint. Any idea?

<script>
  $(document).ready(function() {

    $("#getMessage").on("click", function(){
      // Only change code below this line.

      $.getJSON("/json/cats.json", function(json) {
        $(".message").html(JSON.stringify(json));
       });

      // Only change code above this line.
    });

  });
</script>

<div class="container-fluid">
  <div class = "row text-center">
    <h2>Cat Photo Finder</h2>
  </div>

It should not bit a big problema because the own waypoint description tells you what you have to copy and paste in the code box, but on the result screen I only get error code and it shoul be images...

bitgrower
@bitgrower
Feb 20 2016 09:19
(and I have about 10 minutes left before I turn into a pumpkin ...
@Abel1987 -- sometimes it takes a little bit for the images to show up ...
Dulshani Gunawardhana
@dshgna
Feb 20 2016 09:22
so we need the smallest common multiple between two numbers x and y. Now, to get the least common multiple, we can take the prime factors of each number and get the least multiple by multiplying the largest number of times each prime factor occurs.
For example:
2,4,6
2 = 1x2
4 = 2x2
6 = 2x3
LCM = 2x2x3
So what I've been trying to do is first get the prime factors for each number. In a case where the prime factor occurs lesser times than the max noted so far, its not needed and discarded.
@bitgrower
bitgrower
@bitgrower
Feb 20 2016 09:24
okay ... what's the easiest way to get the prime factors for your ultimate answer ...
(note -- I do not know if what I'm asking is a more efficient way of doing this ... just happens to be how I approached the problem ... )
okay ... I'm running out of time ... would you like me to tell you how I think my solution differs from yours ?
okay ... looks like time's up ... I'll leave you with a hint ... I first just find all the prime numbers in the range ...
Dulshani Gunawardhana
@dshgna
Feb 20 2016 09:28

@bitgrower first I divided by two. then 3 onwards I went up (2 at a time) upto the square root of that number. And in the case where the number itself is a prime number and doesn't have and factors, I added that case at the bottom.

    //first check divisibility by first prime: two
    var n = getFactorCount(number, 2);
    //then for all odd numbers
    for(var d=3; d<=Math.sqrt(number); d +=2){
      n = getFactorCount(n, d);
    }
    //in the case that the number is itself a prime number
    if(n===number && n!==1){
      factors[number] = 1; 
    }

To count the amount of times each prime factor occurs I've used this:

  //get the number of times that a prime factor is repeated in division
  function getFactorCount(num, div){
    var count = 0; 
    while( num%div === 0 ){
      num = num/div;
      count++;
    }
    if (factors.hasOwnProperty(""+div) && count>factors[""+div]){
      factors[""+div] = count;
    } else if (!factors.hasOwnProperty(""+div) && count>0) { 
      factors[""+div] = count; 
    }
    return num;
  }
bitgrower
@bitgrower
Feb 20 2016 09:29
okay ... until we meet again ... think about what I've done ... and why I would do that, and how it could remove a lot of effort ... :)
Pedro Abel Díaz Sánchez
@coderHook
Feb 20 2016 09:29

@bitgrower this is what I get from the resut box aka the mobile on the right side:

[{"id":0,"imageLink":"https://s3.amazonaws.com/freecodecamp/funny-cat.jpg","codeNames":["Juggernaut","Mrs. Wallace","Buttercup"]},{"id":1,"imageLink":"https://s3.amazonaws.com/freecodecamp/grumpy-cat.jpg","codeNames":["Oscar","Scrooge","Tyrion"]},{"id":2,"imageLink":"https://s3.amazonaws.com/freecodecamp/mischievous-cat.jpg","codeNames":["The Doctor","Loki","Joker"]}]

I do not think it is a matter of time.

Neeraj Lad
@neeraj-lad
Feb 20 2016 09:29
@bitgrower @dshgna an easier way would be:
Get the smallest & largest nos. Take a loop starting from the largest no. See if all the numbers in the range [smallest, largest] divide by it. If yes, you return the number, else continue.
bitgrower
@bitgrower
Feb 20 2016 09:30
easier, not necessarily the most efficient ...
Neeraj Lad
@neeraj-lad
Feb 20 2016 09:30
true.. inefficient
bitgrower
@bitgrower
Feb 20 2016 09:30
@Abel1987 -- I believe that your code is doing exactly what it should be doing :) It's showing you the raw JSON output ... :)
someone say my name in a minute or two so I can easily find my way back to your conversation when I get up tomorrow (er, later today) ...
Dulshani Gunawardhana
@dshgna
Feb 20 2016 09:33
@neeraj-lad that could go on for a very long time
@bitgrower that's the best way I could think of :D
@neeraj-lad think a large range like [1, 900000]
Neeraj Lad
@neeraj-lad
Feb 20 2016 09:34
@dshgna haha.. yes. It was a brute force solution. Definitely not the most efficient.
Dulshani Gunawardhana
@dshgna
Feb 20 2016 09:37
@neeraj-lad done with the wiki viewer :D?
Manan Kalra
@manankalra
Feb 20 2016 09:37
function chunk(arr, size) {
  var temp = [];
  //console.log(arr);
  for(var i=0;i<arr.length;i+=size){
    temp.push(arr.slice(i, i+size));
  }  
  //console.log(temp);
  return temp;
  }

chunk(["a", "b", "c", "d", "e"], 2);
@bitgrower @revisualize
That was really easy! Idk why I was trying to make it difficult!
Will now check that debugging stuff that you suggested. @NickEU
Thanks! :)
CamperBot
@camperbot
Feb 20 2016 09:37
manankalra sends brownie points to @bitgrower and @revisualize and @nickeu :sparkles: :thumbsup: :sparkles:
:star: 603 | @revisualize | http://www.freecodecamp.com/revisualize
:star: 379 | @nickeu | http://www.freecodecamp.com/nickeu
:star: 597 | @bitgrower | http://www.freecodecamp.com/bitgrower