These are chat archives for FreeCodeCamp/HelpJavaScript

29th
Jul 2017
Kelechi Chinaka
@ke1echi
Jul 29 2017 00:00
i think cw is becoming difficult :smile: @kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 29 2017 00:04
I think... probably 3 is my limit at the moment :laughing:
Kelechi Chinaka
@ke1echi
Jul 29 2017 00:06
cool :smile: 5 seems magical to me ..lol
kumquatfelafel
@kumquatfelafel
Jul 29 2017 00:09
It depends a bit on problem as well sometimes. I've seen 1's and 2's that look doable (but I don't particularly desire doing at moment) and 4's and 5's where I genuinely have no clue.
Kelechi Chinaka
@ke1echi
Jul 29 2017 00:11
yea..true
monkeyfingerz
@monkeyfingerz
Jul 29 2017 00:12
function sym() {
  var argumentArray = [];
  var holderArray=[];
  //creates one multi-array of all arguements
  for (var i = 0; i < arguments.length; i++) {
    argumentArray.push(arguments[i]);
  }
  //creates one array from the multi-array
  var oneArray =argumentArray.reduce(function(a,b){
    return a.concat(b);
  });
  //this sorts through the array from low to high chrono.
  var sortedArray= oneArray.sort(function(a,b){
    return a -b;
  });
  // This loop continues until every element has been sliced out of the sortedArray
 while(sortedArray.length>0){
  //getting distance of first and last index of element
  var firstApp = sortedArray.indexOf(sortedArray[0]);
  var lastApp = sortedArray.lastIndexOf(sortedArray[0]);
 // this if statement checks to see if there is an odd number of the first element, pushes one if it is odd, then slices all of the element out of the array  
   if((lastApp-firstApp+1)%2===1){  

      holderArray.push(sortedArray[0]);

     sortedArray.slice(firstApp,lastApp);
 }else{
   sortedArray.slice(firstApp,lastApp+1);
 }

       }


}
sym([1, 2, 3], [5, 2, 1, 4]);
I'm getting an infinite loop . i think on the while statement . any help is appreciated
kumquatfelafel
@kumquatfelafel
Jul 29 2017 00:13
@monkeyfingerz slice doesn't modify sortedArray, it returns a new array
monkeyfingerz
@monkeyfingerz
Jul 29 2017 00:14
@kumquatfelafel SHoooot
@kumquatfelafel thanks
CamperBot
@camperbot
Jul 29 2017 00:14
monkeyfingerz sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 549 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 29 2017 00:17
np
may be other issues as well, haven't really looked closely. That just stood out.
Kelechi Chinaka
@ke1echi
Jul 29 2017 00:19
yea
how has the learning curve been for you @kumquatfelafel
Luminary
@Edsheerans
Jul 29 2017 00:24
who know how to send images in the chat?
for(var i=0;i<4;i++)
{ if(contacts[i].firstName==firstName)
{
if(contacts[i].firstName.prop!==null)
{
return contacts[i].firstName.prop;
}
else
{
return "No such property";
}
}
else
{
return "No such contact";
}
}

我们有一个对象数组,里面存储着通讯录。

函数 lookUp 有两个预定义参数:firstName值和prop属性 。

函数将会检查通讯录中是否存在一个与传入的 firstName 相同的联系人。如果存在,那么还需要检查对应的联系人中是否存在 prop属性。

如果它们都存在,函数返回prop属性对应的值。

如果firstName 值不存在,返回 "No such contact"。

如果prop 属性不存在,返回 "No such property"

kumquatfelafel
@kumquatfelafel
Jul 29 2017 00:27
just gonna reformat this.
for(var i=0;i<4;i++) {    
  if(contacts[i].firstName==firstName){
    if(contacts[i].firstName.prop!==null){
      return contacts[i].firstName.prop;
    } else {
      return "No such property";
    }
  } else {
    return "No such contact";
  }
}
Kelechi Chinaka
@ke1echi
Jul 29 2017 00:30
put your code inside backticks
kumquatfelafel
@kumquatfelafel
Jul 29 2017 00:35

@Edsheerans first things first, return statements will end the execution of the function and return the specified value.

...

Say I'm looking through contacts on my phone to see if my friend is in my contacts. Now, suppose I check the first contact. It's not my friend. Do I know for a fact, after checking only one contact, that my friend isn't one of my contacts?

Second of all, what is 4 in your code? What is its significance?
kumquatfelafel
@kumquatfelafel
Jul 29 2017 00:48
contacts[i].firstName.prop
here you are saying, "get me the property, prop, of the property firstName, of contacts[i]"
This is not what you want.
Nick Cleary
@Hijerboa
Jul 29 2017 01:04

Can anyone explain why there is an "undefined" appearing in my offline array? https://codepen.io/hijerboa/pen/XgLQpd?editors=0012

Judging by chrome's dev tools, the only time it appears is when it's being queried to see it's status after being added to the offline array. There doesn't seem to be any logical reason why it's being added
Even after removing my non existent user "test case" it still appears
_

Stephen James
@sjames1958gm
Jul 29 2017 01:13
@kelechy That one was interesting kata
Kelechi Chinaka
@ke1echi
Jul 29 2017 01:14
which to be specific? @sjames1958gm
Stephen James
@sjames1958gm
Jul 29 2017 01:15
@kelechy Base conversion one
Kelechi Chinaka
@ke1echi
Jul 29 2017 01:16
wow.. i didnt try @sjames1958gm
Stephen James
@sjames1958gm
Jul 29 2017 01:16
Sorry that was
@kumquatfelafel
@Hijerboa Because your code for if (info.error == "Not Found") { falls through and pushes onto offline array.
You should have an else for this
@Hijerboa
                if (info.error == "Not Found") {
                    nonExist.push(streamers[streamIndex]);
                    //If more streamers are available, call function again
                    if (++streamIndex < streamers.length) {
                        getStatus(streamers[streamIndex]); return;
                    }
                }
                else { // without this else your code was calling push when info.error === "Not Found"
                    offline.push(streamers[streamIndex]);
                    console.log(offline);
                    if (++streamIndex < streamers.length) {
                        getStatus(streamers[streamIndex]);
                    }
                }
kumquatfelafel
@kumquatfelafel
Jul 29 2017 01:45
@sjames1958gm Feel like will enjoy. Just deciding now if way I want to do it is way I really want to do it. :p
Stephen James
@sjames1958gm
Jul 29 2017 01:45
@kumquatfelafel lol
John
@AnonymousLords
Jul 29 2017 01:55
Guys how to test for punction, spaces or symbols? Like what would i use in a regular expression to test for those?
Stephen James
@sjames1958gm
Jul 29 2017 01:56
@AnonymousLords There are a couple of ways (or more) /[^0-9a-zA-Z]/ or /\W|_/
John
@AnonymousLords
Jul 29 2017 01:56
/[^0-9a-zA-Z]/
what does 0-9 mean
kumquatfelafel
@kumquatfelafel
Jul 29 2017 01:56
0 through 9
(when inside [])
John
@AnonymousLords
Jul 29 2017 01:56
So 0-9, all lowercase letters, and all capital letters
kumquatfelafel
@kumquatfelafel
Jul 29 2017 01:57
And the ^ inside [] means not.
John
@AnonymousLords
Jul 29 2017 01:57
Oh okay
humm
now what does /\W|_/ do?
kumquatfelafel
@kumquatfelafel
Jul 29 2017 01:58
| means or
more or less
John
@AnonymousLords
Jul 29 2017 01:59
W?
Stephen James
@sjames1958gm
Jul 29 2017 01:59
\W is the opposite of \w where \w matches all word characters which is letters numbers and underscore
so \W matches everything but those -
John
@AnonymousLords
Jul 29 2017 02:00
ok
Now i want to remove all punction, numbers andsymbols
this is my code so far
function palindrome(str) {
 str.replace(/[^0-9a-z]/g, "")


}
You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything lower case in order to check for palindromes.
Stephen James
@sjames1958gm
Jul 29 2017 02:02
@AnonymousLords replace like all string functions returns a new string
Raiden357
@raiden357
Jul 29 2017 02:03
ES6: Write Arrow Functions with Parameters can someone help, I'm lost
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:03
@raiden357 link/post code
John
@AnonymousLords
Jul 29 2017 02:04
Now is their a remove function? Or do i just have to use replace
Raiden357
@raiden357
Jul 29 2017 02:04
@kumquatfelafel . damn I just got it. lol. thanks
CamperBot
@camperbot
Jul 29 2017 02:04
raiden357 sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 550 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Stephen James
@sjames1958gm
Jul 29 2017 02:04
@AnonymousLords you need to use toLowerCase, or A-Z or i flag to not remove A-Z
but replace is what you want
John
@AnonymousLords
Jul 29 2017 02:05
You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything lower case in order to check for palindromes.
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:05
@raiden357 lol. You're welcome.
As you can see, I always give it 110% to help those in need. :p
I mean, me saying anything at all is like a good luck charm! :o
;)
John
@AnonymousLords
Jul 29 2017 02:05
SO put those non-alphanumeric characters into a separate place?
Stephen James
@sjames1958gm
Jul 29 2017 02:05
@AnonymousLords var newstr = str.replace()
Raiden357
@raiden357
Jul 29 2017 02:07
@kumquatfelafel I believe
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:07
haha
John
@AnonymousLords
Jul 29 2017 02:07
Now what do i replace the non-alpha characters with?
Matthew
@mtphil
Jul 29 2017 02:07
@AnonymousLords Nothing
Empty string
“”
John
@AnonymousLords
Jul 29 2017 02:07
So hell1o will be hello
Matthew
@mtphil
Jul 29 2017 02:07
That’s the idea
John
@AnonymousLords
Jul 29 2017 02:08
function palindrome(str) {
var newStr = str.replace(/[^0-9a-z]/g, "");
newStr = newStr.toLowerCase;
}
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:09
@AnonymousLords *hell1o will be hell1o
John
@AnonymousLords
Jul 29 2017 02:10
will /[0-9]/g test for numbers and replace?
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:10
You don't want to replace numbers here
But yes, it would.
Matthew
@mtphil
Jul 29 2017 02:10
Yeah, it says “non-alphanumerics"
alphanumerics = all letters and numbers
so you’re removing everything BUT letters and numbers
in terms of regex
you’re looking for
/[\W_]/g
John
@AnonymousLords
Jul 29 2017 02:12
^0-9a-z seems a easier to read lol
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:13
The one thing is, a-z includes all lowercase, but not uppercase.
You either need to include A-Z explicitly, or add an i flag next to your g, which lets it know to ignore case.
John
@AnonymousLords
Jul 29 2017 02:14
Well it also needs to filter uppercase
so toLowerCase
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:15

toLowerCase

Doing this first would be a legitimate solution.

John
@AnonymousLords
Jul 29 2017 02:16
Do before the replace?
Oh because uppercase will be deleted
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:17
yep! Methods called earlier take effect first
John
@AnonymousLords
Jul 29 2017 02:18
okay
Should not of drank a whole diet coke
brb
back :P
rev = newStr.reverse(); is not a function? @kumquatfelafel @mtphil
John
@AnonymousLords
Jul 29 2017 02:24
only arrays?
@kumquatfelafel ello?
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:26
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
Who knows? If there's a reverse for string it'll be in list of methods. ;)
John
@AnonymousLords
Jul 29 2017 02:28
String.fromCharCode() String.fromCodePoint() String.raw()
.match :D?
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:30

:p

So reverse isn't there right? But it is there for arrays.

John
@AnonymousLords
Jul 29 2017 02:31
?
Am i close though with my code?
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:32
I haven't actually seen your code, but for the time being it sounds like you're on the right track, or at least understand more or less what needs to happen, even if you're not 100% sure how to go about that.
John
@AnonymousLords
Jul 29 2017 02:33
function palindrome(str) {
str.toLowerCase;
var newStr = str.replace(/[^0-9a-]/g, "");
rev = newStr;
rev = newStr.reverse();
if (rev = newStr) {
  return true;
}
return false;
}
I feel like has too many varaibles
i used rev to save a copy before reverse
Then compared
But newStr.reverse(); isn't a function
No errors else wise that i know of
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:34
yup.
well... we'll come back to that in a moment. There are a couple problems with what you have.
John
@AnonymousLords
Jul 29 2017 02:35
O_o
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:35

/[^0-9a-]/g

a-?

John
@AnonymousLords
Jul 29 2017 02:36
Whoops typo
Okay fixed that a-z
Does it need to reverse the parameters directly, not a variable? @kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:39

str.toLowerCase;

so first off, this doesn't actually call the toLowerCase function, it just references.

Also, string functions that return a string generally do not modify the original string because strings are "immutable". Instead, these functions return a new string. If you don't store that in a variable, then it is lost.

John
@AnonymousLords
Jul 29 2017 02:40
okay so str = str.toLowerCase
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:41
Without (), you are not storing the result of a function call, but... well... it's more like you're storing the function itself.
str = str.toLowerCase;
str() //calls toLowerCase
str = str.toLowerCase() // returns lowercase string and stores in str
John
@AnonymousLords
Jul 29 2017 02:42
okay so str.toLowerCase();
function palindrome(str) {
str = str.toLowerCase();
var newStr = str.replace(/[^0-9a-z]/g, "");
rev = newStr;
rev = newStr.reverse();
if (rev = newStr) {
  return true;
}
return false;
}



palindrome("hell1o")
Kei Nart
@codenart
Jul 29 2017 02:46
@AnonymousLords :+1:
John
@AnonymousLords
Jul 29 2017 02:46
rev = newStr.reverse(); is not a function
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:47

@AnonymousLords Okay, so from here, you had the idea of calling reverse().

So, as we established earlier, there is no reverse function in string (otherwise it would have been in that list of methods you were looking at). However, there is a reverse function for arrays.

John
@AnonymousLords
Jul 29 2017 02:47
OHH
So join split and join again into array?
split reverse join
kumquatfelafel
@kumquatfelafel
Jul 29 2017 02:48
Maybe. Try and see how it goes. ;)
Austin Wiggins
@austinwiggins
Jul 29 2017 02:48
I just finished my weather app project after tons of work. I would really like some feedback on it: https://codepen.io/bigwigaustin/pen/vZxJeP Thanks!
John
@AnonymousLords
Jul 29 2017 02:50
@kumquatfelafel
function palindrome(str) {
str = str.toLowerCase();
var newStr = str.replace(/[^0-9a-z]/g, "");
rev = newStr;
newStr.split();
newStr.reverse();
newStr.join('');
if (rev = newStr) {
  return true;
}
return false;
}



palindrome("hell1o")
@austinwiggins Looks good, needs more of a background that is slight transparent
(\opacity)
Austin Wiggins
@austinwiggins
Jul 29 2017 02:51
@AnonymousLords thanks for the feedback, I'll do that. :)
CamperBot
@camperbot
Jul 29 2017 02:51
:cookie: 297 | @anonymouslords |http://www.freecodecamp.com/anonymouslords
austinwiggins sends brownie points to @anonymouslords :sparkles: :thumbsup: :sparkles:
John
@AnonymousLords
Jul 29 2017 02:52
@kumquatfelafel do i need to assign split to a variable?
@kumquatfelafel I used a varaibel with split
John
@AnonymousLords
Jul 29 2017 02:57
almost their, mostly correct
Guderian Raborg
@hypercuber
Jul 29 2017 02:59
What is the easiest way to put canvas in center of page:
    <canvas></canvas>
body {
  margin: 0;
}

canvas {
  border: 1px solid black;
  background-color: black;
}

let canvas = document.querySelector('canvas');

canvas.width = 200;
canvas.height = 200;

let c = canvas.getContext('2d');
I was thinking flex
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:01

@AnonymousLords It's good to check the documentation of methods you're using/unfamiliar with. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split

There are certain things that I always look out for:

Parameters: this section describes what arguments can/need to be passed in, and a bit about what they are/do.
Return Value: this tells us what is actually returned as a result of calling this function.

I also tend to look at a couple of the provided examples to get a feel for how function works in actual practice.

If you can get used to reading documentation, it will give you a huge leg up since (as long as something is well documented) it means you can pretty much figure out what anything does, even if you're coming from a place of complete unfamiliarity.

John
@AnonymousLords
Jul 29 2017 03:02
@kumquatfelafel Okay
I used that split

function palindrome(str) {
str = str.toLowerCase();
var newStr = str.replace(/[^0-9a-z]/g, "");
var rev = newStr;
var array = newStr.split();
array.reverse();
array.join('');
if (rev == array) {
  return true;
}
return false;
}
doesnt work
"not a palindrome" returns true
Everything returns true :large_blue_circle:
:L
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:05
array.join(''); does not modify array. Returns new string.
John
@AnonymousLords
Jul 29 2017 03:06
@kumquatfelafel so array = arrayjoin();
What makes it auto return true?
No mater the parameter
i think its something with my if statement
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:11
It's actually related to your split.
John
@AnonymousLords
Jul 29 2017 03:11
split("")
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:11
yup.
John
@AnonymousLords
Jul 29 2017 03:12
okay i fixed that, now eveything still returns true
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:12
post code
John
@AnonymousLords
Jul 29 2017 03:13
function palindrome(str) {
str = str.toLowerCase();
var newStr = str.replace(/[^0-9a-z]/g, "");
rev = newStr;
var array = newStr.split('');
array.reverse();
array = array.join('');
if (rev == array) {
  return true;
}
return false;
}
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:14

if (rev = array)

Is this how we compare two values?

John
@AnonymousLords
Jul 29 2017 03:14
Yes i just fixed that with ==
It worked! :D
a thousand thanks @AnonymousLords @kumquatfelafel @codenart
CamperBot
@camperbot
Jul 29 2017 03:14
anonymouslords sends brownie points to @kumquatfelafel and @codenart :sparkles: :thumbsup: :sparkles:
:cookie: 369 | @codenart |http://www.freecodecamp.com/codenart
:cookie: 551 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:15
@AnonymousLords k... so it worked. But it can also be shorter.
John
@AnonymousLords
Jul 29 2017 03:15
:O
O_O
E-mc2
What would that look like?
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:15
@AnonymousLords the key here is chaining methods.
John
@AnonymousLords
Jul 29 2017 03:16
okay
i gtg in like 5 minutes so :P
thanks anywasy though
Post what it would like like or a hint ill check later
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:18

Say I want to convert a string, "Hello World", to upper case, then get rid of spaces.

var str = "Hello World".toUpperCase().replace(/ /g, '');

This is possible because toUpperCase() returns a string, on which further string functions can be called. @AnonymousLords
So knowing the return value of a function is very important, as you may be able to call a function on the return value itself.
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:25

Another way I could perform above action (also only possible from knowing return value of these functions well, is
var str = "Hello World".toUpperCase().split(" ").join("");

This isn't to say one should do it this way, but note that in the process of doing these functions, the result is a string, then an array, then a string again.

@AnonymousLords
So see if you can play around with this, and by looking at the documentation for these methods (google will work fine) and the respective return values, you can make your code a bit cleaner.
slertka
@slertka
Jul 29 2017 03:32
Hi -- I need help with my twitch API project! I want to 'color code' the online and offline channels but can't figure out how to do this! Here's my codepen: https://codepen.io/slertka/pen/ZydWpa?editors=0010
Jan Shah
@JanShah
Jul 29 2017 03:37
@slertka
.online{
  background:blue;
}
just add that to css
slertka
@slertka
Jul 29 2017 03:39
omg i did that and it wasn't working.... thanks much lol
@JanShah thanks!
mauriciodeleonc
@mauriciodeleonc
Jul 29 2017 03:40
function mutation(arr) {

  for (var i = 0; i < arr.length; i++) {
    arr[i] = arr[i].toLowerCase();   
  }

  for (var j = 0; j < arr[1].length; j++) {
      arr[1][j] = arr[1][j].split("");
    }
  console.log(arr[1][j]);

}

mutation(["hello", "hey"]);
heeey
im just experimenting with this challenge here
but i dont know why, it gives me an error saying "0 is read only"
tbh, im not sure what that means or where that is seen in the code
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:42
@mauriciodeleonc strings are immutable.
actually, sec. lemme check challenge again
mauriciodeleonc
@mauriciodeleonc
Jul 29 2017 03:44
hmm sorry, but still dont understand it
why if i do this
for (var i = 0; i < arr.length; i++) {
    arr[i] = arr[i].toLowerCase(),split("");   
  }
it does work but when separated it doesnt?
(sorry i wrote a "," instead of a ".")
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:46

@mauriciodeleonc Okay. Yes. Strings are immutable.

for (var i = 0; i < arr.length; i++) {
    arr[i] = arr[i].toLowerCase();   
}

:point_up: here you've replaced the two strings with their lower case equivalent.

:point_down: here, arr[1][j] is the jth character of string arr[1]. So you are telling it to change the jth character of arr[1] to whatever is on right hand side of =.

for (var j = 0; j < arr[1].length; j++) {
      arr[1][j] = arr[1][j].split("");
}
@mauriciodeleonc Those functions are being stored in two very different locations.
mauriciodeleonc
@mauriciodeleonc
Jul 29 2017 03:48
mmm yeah, thats what i was trying to do
ohhhh okay okay
 for (var i = 0; i < arr.length; i++) {
      if (i == 1) {
        arr[i] = arr[i].toLowerCase().split("");
      } else {
        arr[i] = arr[i].toLowerCase();
      }
  }
  console.log(arr[1]);
i changed it to that
and well now it "works" with what i was trying to do
still...with that if/else , is that still immutable or not?
now, just another quick question... if i declare my counter (i) outside of a loop if i want to use it for another loop in the future, will it automatically change back to the value it had before?
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:52

@mauriciodeleonc Here, toLowerCase() doesn't actually try to modify the original string, it returns a new string. And so long as arr is an array, not a string, changing the value at that index is perfectly okay.

While strings are immutable, arrays are not.

mauriciodeleonc
@mauriciodeleonc
Jul 29 2017 03:52
or how does that work?
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:55
@mauriciodeleonc Automatically? No. That being said, if you reassign it a new value in the subsequent for loop, it will take that value.... assignment is assignment.
mauriciodeleonc
@mauriciodeleonc
Jul 29 2017 03:55
okay okay, got it
thanks @kumquatfelafel
CamperBot
@camperbot
Jul 29 2017 03:55
mauriciodeleonc sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 552 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:56
so if had something like
var i = 7;
for ( i = 10; blah; blah) {
  //i starts at 10.
}
mauriciodeleonc
@mauriciodeleonc
Jul 29 2017 03:59
okay so i solved the challenge, and this is how i did it

function mutation(arr) {

  var count = 0; 

  for (var i = 0; i < arr.length; i++) {
      if (i == 1) {
        arr[i] = arr[i].toLowerCase().split("");
           for (var j = 0; j < arr[i].length; j++) {
             if (arr[0].includes(arr[1][j])) {
               count++;
             }
           }
        } else {
            arr[i] = arr[i].toLowerCase();
          }
    }



  if (count == arr[1].length) {
    return true;
  } else {
    return false;
  }


}

mutation(["hello", "hey"]);
i know the logic can be a bit confusing and there must obviously be an easier and shorter way of solving it
kumquatfelafel
@kumquatfelafel
Jul 29 2017 03:59
off for now. night :)
mauriciodeleonc
@mauriciodeleonc
Jul 29 2017 03:59
but i have a doubt....i that last if/else statement
hahah night
in that if/else statement...if i didnt write those "true" and "false" it would´ve never solved the challenge, so...wasnt that supposed to return by "default" true or false without having to "ask" it to return it?
Ken Haduch
@khaduch
Jul 29 2017 04:05
@mauriciodeleonc - if you end a function without any return statement, it will return undefined by default. But you should not have to do what you are doing to explicitly return true or false, you should just be able to do return count == arr[1].length; and it should return the results of the comparison. A lot simpler.
mauriciodeleonc
@mauriciodeleonc
Jul 29 2017 04:06
without the whole if/else?
Ken Haduch
@khaduch
Jul 29 2017 04:07
@mauriciodeleonc - yes, it should have been covered in one of the lessons. Try it and see if it still works?
mauriciodeleonc
@mauriciodeleonc
Jul 29 2017 04:09
yep it works...and maybe it was covered in one of the lessons, but i dont remember them that much
thanks @khaduch
CamperBot
@camperbot
Jul 29 2017 04:09
mauriciodeleonc sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3147 | @khaduch |http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Jul 29 2017 04:10
@mauriciodeleonc - if you have done the lesson, it would have been in "Returning Boolean Values from Functions" - but it might not have been something that you got to up to this point. Or something that you just didn't grasp at the time - but you can see how it works, and if you review that lesson you'll see a little more detail. The more you use these things in practice, the more natural they become. It's hard to remember it all the first time through!
@mauriciodeleonc - you're welcome.
mauriciodeleonc
@mauriciodeleonc
Jul 29 2017 04:11
yeaah haha, thats kind of a problem, trying to remember it all
but thank you so much
Ken Haduch
@khaduch
Jul 29 2017 04:12
@mauriciodeleonc - believe me, I know how much trouble it can be! It takes a lot of practice, and knowing where to look in the documentation. Little by little it gets in there...
Peter Kay
@deuscode
Jul 29 2017 05:46
Hey friends, trying to do the spinal tap algorithm challenge and having a problem on matching all of the challenges.
function spinalCase(str) {

  var strToChange = str.split(/(?=[A-Z])/)

  for (var i = 0; i < strToChange.length; i++) {
    strToChange[i] = strToChange[i].toLowerCase().replace(/\s|_/g, '');

  }

  return strToChange.join("-");
  //return strToChange
}
spinalCase('Teletubbies say Eh-oh');
I'm getting the Teletubbies part wrong, but am stuck on how to go about this
spinalCase("This Is Spinal Tap") should return "this-is-spinal-tap".
spinalCase("thisIsSpinalTap") should return "this-is-spinal-tap".
spinalCase("The_Andy_Griffith_Show") should return "the-andy-griffith-show".
spinalCase("Teletubbies say Eh-oh") should return "teletubbies-say-eh-oh".
spinalCase("AllThe-small Things") should return "all-the-small-things".
since the regex split can't pick up the lowercase after the space
how would I modify my regex to capture that?
never mind
foudn the solution
lol
var strToChange = str.split(/(?=[A-Z])|\s(?=[a-z])/)
Revanth Kumar Reddy
@VoduruRevanth
Jul 29 2017 06:46

Hi All, I have issues with check for palindrome challenge
Please check my code and let me know where I am coding wrong
function palindrome(str) {
// Good luck!
var re = '/[^a-zA-Z/d :]/g';

str = str.split('');
str = str.toString().replace(str,re).toLowerCase();
str = str.reverse().join('');
return true;
}

palindrome("eye");

Nitin Sahu
@globefire
Jul 29 2017 06:51

function destroyer(arr) {
  // Remove all the values
  var i, j;
  for(i=1; i < arr.length; i++){
    for(j = 0; j < arr[0].length; j++){
      if(a[0][j] === a[i]){
        arr[0].splice(j, 1);
      }
    }
  }
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
i can't get what's wrong in it, can someone help me ?
Kei Nart
@codenart
Jul 29 2017 07:22
@deuscode @VoduruRevanth @globefire Hi all :clap:
Adam Faraj
@adamfaraj
Jul 29 2017 07:22
@VoduruRevanth did you get it?
Manish Giri
@Manish-Giri
Jul 29 2017 07:24
@globefire if(a[0][j] === a[i]){
what's a
Adam Faraj
@adamfaraj
Jul 29 2017 07:26
@Manish-Giri whats the whole code?
the context
Fabien SHAN
@X140hu4
Jul 29 2017 07:31
@globefire Try to return the different arguments in the destroyer call.
Markus Kiili
@Masd925
Jul 29 2017 07:31
@globefire arr only holds the first passed argument, for example [1, 2, 3, 1, 2, 3] here.
vincent5460
@vincent5460
Jul 29 2017 08:21

function golfScore(par, strokes) {

if(4,1){
return"Hole-in-one!";}

if(4,2)
{
return"Eagle";
}
if
(4,3){
return"Eagle";
}
if(4,4){
return"Par";
}
if(4,5){
return"Bogey";
}
if(4,6){
return"Double Bogey";
}
else
{
return"Go Home";
}}

golfScore(4, 3);

help me .thank you
why it could not pass the lesson?
it only reach the hole in one .the first step
then it could not continue to work .
Revanth Kumar Reddy
@VoduruRevanth
Jul 29 2017 08:24
@adamfaraj : ya got it..
WAINGOR
@WAINGOR
Jul 29 2017 08:24
@vincent5460 welcome, and let me give you a tip: make life easy on yourself and on ppl wanting to help you. ALWAYS put your code between backticks (eg *YOUR CODE*)
` without spaces, then your code, and then another ` without spaces between the backticks
three backticks...
also you did not tell what the exact name of the excercise is where you're stuk at
vincent5460
@vincent5460
Jul 29 2017 08:28
golf code
function golfScore(par, strokes) {
if(4,1){
return"Hole-in-one!";}
if(4,2)
{return"Eagle"; }
if(4,3){
return"Eagle";}
if(4,4){
return"Par";}
if(4,5){
return"Bogey";}
if(4,6){return"Double Bogey"; }
else
{return"Go Home";
}}
it could not pass the lesson
Darth Skywalker
@AdiSkywalker
Jul 29 2017 08:29
@vincent5460 if(4,1){ will ALWAYS be true and hence it will always return Hole-in-one!
Right syntax is if(strokes >= 1 && strokes < 4)
and so on
WAINGOR
@WAINGOR
Jul 29 2017 08:33
@vincent please put your code between backticks... ```
code
Do you see the difference?
NOT GOOD:
function golfScore(par, strokes) {
if(4,1){
return"Hole-in-one!";}
if(4,2)
{return"Eagle"; }
if(4,3){
return"Eagle";}
if(4,4){
return"Par";}
if(4,5){
return"Bogey";}
if(4,6){return"Double Bogey"; }
else
{return"Go Home";
}}
GOOD:
function golfScore(par, strokes) {
 if(4,1){
    return"Hole-in-one!";} 
    if(4,2)
   {return"Eagle"; } 
    if(4,3){
        return"Eagle";}
     if(4,4){
      return"Par";}
    if(4,5){
     return"Bogey";}
     if(4,6){return"Double Bogey"; }
    else
      {return"Go Home";
    }}
vincent5460
@vincent5460
Jul 29 2017 08:36
sorry ,i can not find the difference between the good and not good
Darth Skywalker
@AdiSkywalker
Jul 29 2017 08:37
lol I can't even imagine how frustrated @WAINGOR might be now :laughing:
vincent5460
@vincent5460
Jul 29 2017 08:39
just for the mistakes of code or for the copy easily to see the code ?
KIm Ford
@kimfucious
Jul 29 2017 08:54

Hi there… I was working on different ways to solve Return Largest Numbers in Arrays, and my thought process was to use map with sort to return all the arrays back in descending order and then return the first element of the array. Considering the code below, I’ve got a couple questions:

1) If I use “arr = arr.map…” in the first instance of map, the entire function returns nothing… Conversely, if I do not include “app = “ to the second instance, that instance of map does nothing. My question is: Is this becuase .sort performs the operation in place or what?

2) Is there a way to chain these two map instances together? If so, what’s the proper syntax?


function largestOfFour(arr) {

arr.map( function (e) {         // <= 'arr = arr.map' ... doesn't work here.
    e.sort( function(a,b) {
      return b - a;
    });
  });

arr = arr.map (function (e) {   // <= removing 'arr =' ... doesn't work here.
    return e[0];
  });

  return arr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Pieter Stokkink
@forkerino
Jul 29 2017 08:58
@kimfucious
1) It doesn't return anything for the first map, because there is no return statement. if you return e after the sorting, you can do arr = arr.map...
2) You can obviously combine them. Instead of return e, you can do return e[0] as well, so you'll end up with an array containing the largest numbers.
KIm Ford
@kimfucious
Jul 29 2017 09:04
@forkerino Thanks mucho for that! I was blinded by the 'return b - a’ in the sort and did not realize that that initial map instance had no return!


function largestOfFour(arr) {

arr = arr.map( function (e) {         
    e.sort( function(a,b) {
      return b - a;
    });
    return e[0];  // <= Yes!!!
  });
  return arr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
CamperBot
@camperbot
Jul 29 2017 09:04
kimfucious sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2893 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jul 29 2017 09:05
@kimfucious you can even do:
return arr.map(......etc.
KIm Ford
@kimfucious
Jul 29 2017 09:08
@forkerino Nice! Thanks again. :+1:
function largestOfFour(arr) {

return arr.map( function (e) {         
    e.sort( function(a,b) {
      return b - a;
    });
    return e[0];  
  });
}
CamperBot
@camperbot
Jul 29 2017 09:08
kimfucious sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: kimfucious already gave forkerino points
teevik
@teevik
Jul 29 2017 09:19
Could also use reduce and not sort, but would do the same thing
Darth Skywalker
@AdiSkywalker
Jul 29 2017 09:21
Another way
function largestOfFour(arr) {
  return arr.map(a => Math.max.apply(null, a));
}
or
function largestOfFour(arr) {
  return arr.map(function(a){
    return Math.max.apply(null, a);
  });
}
Pieter Stokkink
@forkerino
Jul 29 2017 09:37
@AdiSkywalker if you're using ES6 (arrow function), you might as well use Math.max(...a)
Darth Skywalker
@AdiSkywalker
Jul 29 2017 09:38
@forkerino :+1:
correct!
good catch
KIm Ford
@kimfucious
Jul 29 2017 09:42
@teevik @AdiSkywalker Thanks, gents. My question wasn’t really about how to solve the problem, rather than why my particular solution wasn’t doing what I thought it should do. I appreciate your input, regardless :+1: I considered reduce, but couldn’t wrap my mind around it, and thus defaulted to a lazier solution. I will need to look up what apply does… :smile:
CamperBot
@camperbot
Jul 29 2017 09:42
kimfucious sends brownie points to @teevik and @adiskywalker :sparkles: :thumbsup: :sparkles:
:cookie: 217 | @teevik |http://www.freecodecamp.com/teevik
:cookie: 260 | @adiskywalker |http://www.freecodecamp.com/adiskywalker
Darth Skywalker
@AdiSkywalker
Jul 29 2017 09:44
@kimfucious ouch.. I didn't really read your question. I was too much focused on "this is how I'd do it.. take a look" part haha...
KIm Ford
@kimfucious
Jul 29 2017 09:44
@AdiSkywalker No worries… I’m here to learn and you are very helpful :smile:
Darth Skywalker
@AdiSkywalker
Jul 29 2017 09:45
@kimfucious :+1:
KIm Ford
@kimfucious
Jul 29 2017 10:15
@AdiSkywalker FYI: I looked at Math.max and I like how your solution goes straight to the heart of the matter, eliminating the initial sort that I had in my lazy solution. I think yours is actually lazier/smarter, which I think is better.
Darth Skywalker
@AdiSkywalker
Jul 29 2017 10:39
@kimfucious :+1:
Ashraful Islam
@iashraful
Jul 29 2017 10:40
@AmelZekovic hi! sorry, I went out a bit and never came back :D
I had some questions
for every function I write, it obviously requires some sort of input and some data type and may or may not invoke native operations of those data types
^ to ensure I don't have to make a try catch hell everywhere, I always add some checks at start of the function
let areParamsValid = (args1 && arg2 && arg3 && typeof arg1 === 'string' && typeof arg2 === 'number' && Array.isArray(arg3)); if (!areParamsValid) { // take action like throw some error or return null or whatever }
^ is this always necessary
Ashraful Islam
@iashraful
Jul 29 2017 10:45
I mean I see my colleagues never do these, they just assume the params are there and in proper type because they are supposed to be called with those data types knowing that the function will do what it does
teevik
@teevik
Jul 29 2017 10:46
Yeah, most people just assume people will use it correctly
Ashraful Islam
@iashraful
Jul 29 2017 10:46
now, over time, my functions look all weird and messy and if I need to change something, bugs are introduced because I forgot to may be change one of the checks
@teevik I see the point, but I am too afraid that, may be data will come from something like an api which may not send proper data types
but I am beginning to feel that my fears are groundless
I do sometimes, use defaults like so const do_stuff = (arg1 = '', arg2 = [], arg3 = 0, .... ) => { ... }
but if arg is present even if improper type, this will fall off :D
@teevik so you are saying most people don't care about checking then?
I just want to have peace of mind that am not going lazy
teevik
@teevik
Jul 29 2017 10:50
i personally don't do any more than providing default values, not sure about others
Ashraful Islam
@iashraful
Jul 29 2017 10:51
:D that is a encouraging
think I will stop writing these and settle with defaults
Ashraful Islam
@iashraful
Jul 29 2017 11:01
@teevik forgot to say thanks :D
CamperBot
@camperbot
Jul 29 2017 11:01
iashraful sends brownie points to @teevik :sparkles: :thumbsup: :sparkles:
:cookie: 218 | @teevik |http://www.freecodecamp.com/teevik
Anurag Lahon
@anuraglahon16
Jul 29 2017 11:11
What is MEAN stack?
Stephen James
@sjames1958gm
Jul 29 2017 11:13
mongo, express, angular and node
Anurag Lahon
@anuraglahon16
Jul 29 2017 11:14
is it importan to learn
Stephen James
@sjames1958gm
Jul 29 2017 11:16
I don't know how popular it is, I haven't seen any specific requests for it on any job postings I have seen.
The individual parts are probably more important to know / understand.
Darth Skywalker
@AdiSkywalker
Jul 29 2017 11:17
Job descrition for Full Stack JS developer is likely to include those specifications
but in any case, it's a lot more important to know concepts than a particular tech stack
Stephen James
@sjames1958gm
Jul 29 2017 11:18
@AdiSkywalker I would agree!
Darth Skywalker
@AdiSkywalker
Jul 29 2017 11:19
The way restful server is implemented won;t change the methodologies... irrespective of whether it is developed in Java or Node or .NET or whatever
restful server - for example
Diego Mayer
@Chrono79
Jul 29 2017 11:48
@sjames1958gm it could also be a not kind stack ;)
Stephen James
@sjames1958gm
Jul 29 2017 11:51
@Chrono79 True :boom:
Diego Mayer
@Chrono79
Jul 29 2017 11:52
I'm doing a React course of Udemy, but it's mostly (as far as I went) about setting a production environment
So now I'm doing the FCC Alpha React to try to get the basics
Stephen James
@sjames1958gm
Jul 29 2017 12:06
@Chrono79 There is a bit of setup to get the whole compile/bundle thing going.
Alex
@alexandrupintilei
Jul 29 2017 13:17

function diffArray(arr1, arr2) {
var newArr1 = [];
var newArr = arr1.concat(arr2);
console.log(newArr); //Check if code is work

for (var i = 0; i < newArr.length; i++){
console.log(newArr[i]);
if(newArr[i].slice(7, 8) === 4){
newArr.push(newArr1[i]);
console.log(newArr1);
}
};

}
diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);

function diffArray(arr1, arr2) {
   var newArr1 = []; 
 var newArr = arr1.concat(arr2);
          console.log(newArr);    //Check if code is work

for (var i = 0; i < newArr.length; i++){
    console.log(newArr[i]);
  if(newArr[i].slice(7, 8) === 4){
    newArr.push(newArr1[i]);
    console.log(newArr1);
  }
};

}
diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
newArr1 , shouldnt return 4?
Pieter Stokkink
@forkerino
Jul 29 2017 13:21
@alexandrupintilei how can you .slice a number?
that will throw an error
and I'm not exactly sure what your plan is with this code.
Alex
@alexandrupintilei
Jul 29 2017 13:22
i want to ouput 4 from concated array
Pieter Stokkink
@forkerino
Jul 29 2017 13:24
@alexandrupintilei if (newArr[i] === 4) would make more sense. Or if (i === 7)
But again, not sure why you would want to do that?
Diego Mayer
@Chrono79
Jul 29 2017 13:25
@alexandrupintilei newArr1 is an empty array there, you never change its value
Pieter Stokkink
@forkerino
Jul 29 2017 13:26
that as well
Alex
@alexandrupintilei
Jul 29 2017 13:27
thanks for help
Diego Mayer
@Chrono79
Jul 29 2017 13:27
no problem
Stephen James
@sjames1958gm
Jul 29 2017 13:28
@alexandrupintilei And finally you have no return newArr1
kickkick479
@kickkick479
Jul 29 2017 13:33
@alexandrupintilei I hope this would help you.
slice() returns array, so newArr.slice(7, 8) === 4 never became true.
mustimuu
@mustimuu
Jul 29 2017 14:16
hey guys
where do i find the return button on windows?
Ragnorak
@Rrak
Jul 29 2017 14:17
@mustimuu You mean on windows phone!!
mustimuu
@mustimuu
Jul 29 2017 14:17
no no
laptop
teevik
@teevik
Jul 29 2017 14:17
Enter key?
mustimuu
@mustimuu
Jul 29 2017 14:17
hmm
Darth Skywalker
@AdiSkywalker
Jul 29 2017 14:17
Return on mac and enter on windows are same keys
May Kittens Devour Your Soul
@diomed
Jul 29 2017 14:41
hi
what does this mean Uncaught ReferenceError: $ is not defined
<script>
$('input').dateDropper();
</script>
Darth Skywalker
@AdiSkywalker
Jul 29 2017 14:42
@diomed you may have forgot to include jquery
May Kittens Devour Your Soul
@diomed
Jul 29 2017 14:44
oh I just put that code above it
and it should go after it
>.<
Darth Skywalker
@AdiSkywalker
Jul 29 2017 14:44
@diomed Yes.. jQuery must be included before you want to use $
unless you do something like var $;
but in that case it will say $ is not a function :laughing:
May Kittens Devour Your Soul
@diomed
Jul 29 2017 14:47
so looks like it's smarter to inclue jquery in header than just before body ends
Markus Kiili
@Masd925
Jul 29 2017 14:49
@diomed Doesn't matter, but you need to include jQuery before scripts that use it.
May Kittens Devour Your Soul
@diomed
Jul 29 2017 14:51
I did that from the start
alifarooqi
@alifarooqi
Jul 29 2017 15:06
Hello everyone,

I am doing Steamroller Challenge and I have the following code:

var result = [];

function steamrollArray(arr) {
  // I'm a steamroller, baby
  for (var i=0; i<arr.length; i++) {
    if(!Array.isArray(arr[i])) {
      result.push(arr[i]);
    }
    else {
      steamrollArray(arr[i]);
    }
  }
  return result;
}

I am getting the correct results for the tests given, but can't seem to clear the Challenge. (All four tests failed)

teevik
@teevik
Jul 29 2017 15:11
I'm pretty sure the issue is having result var not cleared
Pieter Stokkink
@forkerino
Jul 29 2017 15:12
@alifarooqi declare result inside your function
otherwise it will keep it's value in between tests
alifarooqi
@alifarooqi
Jul 29 2017 15:13
Oh... Thanks :)
teevik
@teevik
Jul 29 2017 15:13
The problem then is it's recursive
Darth Skywalker
@AdiSkywalker
Jul 29 2017 15:13
@forkerino wouldn't that erase all the data in result on each call?
It's getting called recursively
Pieter Stokkink
@forkerino
Jul 29 2017 15:13
@teevik ah, yes
alifarooqi
@alifarooqi
Jul 29 2017 15:13
I'll make another function
Pieter Stokkink
@forkerino
Jul 29 2017 15:14
@AdiSkywalker @teevik altering the else block could fix this, no?
I'm a bit fuzzy
too little sleep
Darth Skywalker
@AdiSkywalker
Jul 29 2017 15:14
Haven't taken a look in detail... :laughing:
teevik
@teevik
Jul 29 2017 15:15
Could keep it recursive using concat
Pieter Stokkink
@forkerino
Jul 29 2017 15:15
yeah, exactly
alifarooqi
@alifarooqi
Jul 29 2017 15:21

This worked:

function steamrollArray(arr) {
  var result = [];
  return flattened(arr, result);
}

function flattened(arr, result) {
  // I'm a steamroller, baby
  for (var i=0; i<arr.length; i++) {
    if(!Array.isArray(arr[i])) {
      result.push(arr[i]);
    }
    else {
      flattened(arr[i], result);
    }
  }
  return result;
}

Thanks all!

Pieter Stokkink
@forkerino
Jul 29 2017 15:22
@alifarooqi you could do that in one function, too, by adding a line to initialize result if it is not passed in as argument.
something like: result = result || []
alifarooqi
@alifarooqi
Jul 29 2017 15:23
Cool
lijunjie
@JerChina
Jul 29 2017 15:24
Escape Sequences in Strings Answer is?????
Abhinav Mishra
@abhinav-m
Jul 29 2017 15:31
Hey guys, im learning about cors, and wondering how can i see the structure of the http request im sending to the server currently
@forkerino :wave:
any idea how can i do this
debugging the XMLhttp request object comes to my mind..
is there a quickway to do this ?
Darth Skywalker
@AdiSkywalker
Jul 29 2017 15:33
@abhinav-thinktank : In chrome dev tools
image.png
Abhinav Mishra
@abhinav-m
Jul 29 2017 15:33
@AdiSkywalker can you give an example
Darth Skywalker
@AdiSkywalker
Jul 29 2017 15:33
See the pic I just posted
click on network tab
and select the request you want to analyze
It will show you all the details like origin, request and response headers
also in detail section, you will see subtabs
Abhinav Mishra
@abhinav-m
Jul 29 2017 15:34
@AdiSkywalker aah, that seems nice.
@AdiSkywalker thanks!
CamperBot
@camperbot
Jul 29 2017 15:34
abhinav-thinktank sends brownie points to @adiskywalker :sparkles: :thumbsup: :sparkles:
:cookie: 270 | @adiskywalker |http://www.freecodecamp.com/adiskywalker
Darth Skywalker
@AdiSkywalker
Jul 29 2017 15:34
headers/preview/response/timing etc
@abhinav-thinktank :+1:
Abhinav Mishra
@abhinav-m
Jul 29 2017 15:35
yeah this is what i wanted , ty again! @AdiSkywalker
CamperBot
@camperbot
Jul 29 2017 15:35
abhinav-thinktank sends brownie points to @adiskywalker :sparkles: :thumbsup: :sparkles:
:warning: abhinav-thinktank already gave adiskywalker points
Abhinav Mishra
@abhinav-m
Jul 29 2017 15:36
Accept:*/* Accept-Encoding:gzip, deflate, sdch, br Accept-Language:en-GB,en-US;q=0.8,en;q=0.6 Connection:keep-alive Host:api.darksky.net Origin:null User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
So the Origin:null is causing an issue
i see.
Darth Skywalker
@AdiSkywalker
Jul 29 2017 15:37
@abhinav-thinktank In your case?
what error are you getting btw?
Abhinav Mishra
@abhinav-m
Jul 29 2017 15:38
@AdiSkywalker yea, i think so, im just reading up and understanding CORS
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
i need to add this to my request as a header.
as far as i understand.
Darth Skywalker
@AdiSkywalker
Jul 29 2017 15:38
is this your server?
or are you using some 3rd party API?
Abhinav Mishra
@abhinav-m
Jul 29 2017 15:39
3rd party
its the weather app thing.
i didn't know what was happening in the background.
so, if it was my server
i wouldn't need it
right
Darth Skywalker
@AdiSkywalker
Jul 29 2017 15:40
As long as you're js code runs on the same domain, you don't need it
if your server is running on port 9080 and your ui is on 8080, it's still cross domain.
but never mind about that yet...
your problem lies in the way you're making the call
Abhinav Mishra
@abhinav-m
Jul 29 2017 15:41
@AdiSkywalker oh, i didn't know about the port part. interesting.
Darth Skywalker
@AdiSkywalker
Jul 29 2017 15:41
can you share your code where you're making the call?
Abhinav Mishra
@abhinav-m
Jul 29 2017 15:41
@AdiSkywalker let me fix it myself, ill share it :) trying to learn
Darth Skywalker
@AdiSkywalker
Jul 29 2017 15:42
:+1:
Abhinav Mishra
@abhinav-m
Jul 29 2017 15:42
was just trying to see whats going on under the hood , to get a better grasp of it.
@AdiSkywalker thanks again!
CamperBot
@camperbot
Jul 29 2017 15:42
abhinav-thinktank sends brownie points to @adiskywalker :sparkles: :thumbsup: :sparkles:
:warning: abhinav-thinktank already gave adiskywalker points
Corentin Whyte
@CorySW
Jul 29 2017 15:46
I don't know how to make the tic tac toe switch from x to o
here's what I came up with
$(".AskX").on("click", function() {
   $(".game").on("click", function() {
      $(this).html("X");
      $(this).addClass("Clicked");
   });
});

if($(".game").hasClass(".Clicked") === true){
       $(this).html("O");
   }else{
      $(this).html("X");
   }
Abhinav Mishra
@abhinav-m
Jul 29 2017 15:48
@CorySW instead of adding a class, you could initialize a variable
@CorySW the simplest way to implement a toggle of any sorts could be to
@CorySW initialize a variable as var toggle = -1
@CorySW multiply it as : toggle*=-1
@CorySW on each move.
Corentin Whyte
@CorySW
Jul 29 2017 15:49
that's a big help thanks !
Abhinav Mishra
@abhinav-m
Jul 29 2017 15:49
@CorySW if its negative -> X moves, if its positive -> O moves
Gunvant Sarpate
@GunvantSr
Jul 29 2017 15:54
Hello Everyone!
Corentin Whyte
@CorySW
Jul 29 2017 15:54
I don't really know where to put it
Hi @GunvantSr
Gunvant Sarpate
@GunvantSr
Jul 29 2017 15:56
<p id="para">Some Text Here</p>
  <button onClick="changeColor('blue');"> Blue </button>
  <button onClick="changeColor('red');"> Red </button>
function changeColor(newColor) {
  var elem = document.getElementById('para');
  elem.style.color = newColor;
}
Whats wrong in above code ??
Stephen James
@sjames1958gm
Jul 29 2017 15:57
@GunvantSr Nothing - it seems to work for me when I put in jsbin
not working for me :(
Stephen James
@sjames1958gm
Jul 29 2017 15:59
@GunvantSr changeColor is not defined error in the dev tools console.
Gunvant Sarpate
@GunvantSr
Jul 29 2017 16:00
how to solve this error?
Stephen James
@sjames1958gm
Jul 29 2017 16:01
Hmm, not sure I loaded a different jsfiddle and it did something similar and it worked
Darth Skywalker
@AdiSkywalker
Jul 29 2017 16:03

@GunvantSr Nothing wrong for me either

https://codepen.io/AdiSkywalker/pen/oebLQE?editors=1010

WAINGOR
@WAINGOR
Jul 29 2017 16:03
Hi guys, I just want to share something with you all
Abhinav Mishra
@abhinav-m
Jul 29 2017 16:04
did my code just get deleted
Gunvant Sarpate
@GunvantSr
Jul 29 2017 16:04
Tried on Codepen working perfectly! whts wrong with JSFiddle ?? :smile:
Abhinav Mishra
@abhinav-m
Jul 29 2017 16:04
window.onload = initAll;

function initAll() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(makeCall)
    } else
        alert("your browser doesn't support this!");

    function makeCall(position) {
        var latitude = position.coords.latitude;
        var longitude = position.coords.longitude;
        var url = "https://api.darksky.net/forecast/b185ccffd3fe5dc262bda8424f07ee7e/" + latitude + "," + longitude;
        var httpReq = new XMLHttpRequest();
        httpReq.open('GET', url, true);
        // httpReq.setRequestHeader('origin', 'Access-Control-Allow-Origin');
        httpReq.setRequestHeader("origin", "http://localhost");
        httpReq.onreadystatechange = callback;
        httpReq.send();

        function callback() {
            document.getElementById("content").innerHTML = httpReq.responseText;

        }
    }

}
So this is what im trying to achieve to learn cors
it gives me an error i can't set the "origin" header on my own
googling around tells me that isn't allowed, the browser does it for you
how can i go about achieving this
Gunvant Sarpate
@GunvantSr
Jul 29 2017 16:04
@WAINGOR Yeah!
Darth Skywalker
@AdiSkywalker
Jul 29 2017 16:05
@abhinav-thinktank won't work that way for cross domain calls
Gunvant Sarpate
@GunvantSr
Jul 29 2017 16:05
@sjames1958gm, @AdiSkywalker Thanks sir
CamperBot
@camperbot
Jul 29 2017 16:05
gunvantsr sends brownie points to @sjames1958gm and @adiskywalker :sparkles: :thumbsup: :sparkles:
:cookie: 274 | @adiskywalker |http://www.freecodecamp.com/adiskywalker
Stephen James
@sjames1958gm
Jul 29 2017 16:05
@GunvantSr In your javascript settings the gear in the javascript panel set wrapping to none - since your js is wrapped in onload - the HTML cannot see your functions
CamperBot
@camperbot
Jul 29 2017 16:05
:star2: 8187 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Abhinav Mishra
@abhinav-m
Jul 29 2017 16:05
@AdiSkywalker is there anyway to make it work
@AdiSkywalker apart from using jquery
Darth Skywalker
@AdiSkywalker
Jul 29 2017 16:05
@abhinav-thinktank Yeah.. .You create a script tag with src set to the cross domain url
and add this tag to your head.
it will execute the request
and get the data back
Abhinav Mishra
@abhinav-m
Jul 29 2017 16:06
huh..
does it now..
let me see..
Stephen James
@sjames1958gm
Jul 29 2017 16:07
@abhinav-thinktank You either have to have a cross origin agreement with the server, or the server supports jsonp.
Or like wikipedia they have an option to allow all origins.
WAINGOR
@WAINGOR
Jul 29 2017 16:07
About a year and 2 months ago I started coding on free platforms like FCC and Code Academy. I didnt have the slightest clue about how to code. All I had was a shitload of debt, a laptop and an attitude. Math was never my strongest skill. Still I landed a job as a frontend dev after 5 months of hard work. And now I am close to finishing my first programme in NodeJS that will generate cold hard cash. I am so grateful to all the OG programmers in this very chat right now, and especially restless and wicked devs by the likes of @sjames1958gm @Blauelf and @forkerino . And offcourse all others in here trying to help. I will never forget the contribution you guys make to this community
CamperBot
@camperbot
Jul 29 2017 16:07
:star2: 8187 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Darth Skywalker
@AdiSkywalker
Jul 29 2017 16:07
@abhinav-thinktank Take a look at this
function foo(data){
    // do stuff with JSON
}

var script = document.createElement('script');
script.src = '//example.com/path/to/jsonp?callback=foo' // foo is defined here

document.getElementsByTagName('head')[0].appendChild(script);
Abhinav Mishra
@abhinav-m
Jul 29 2017 16:07
@sjames1958gm how does stuff like crossoriginme work
@WAINGOR congrats :)
WAINGOR
@WAINGOR
Jul 29 2017 16:08
<3
Darth Skywalker
@AdiSkywalker
Jul 29 2017 16:08
@WAINGOR Nailed it mate!!! Cheerio!
WAINGOR
@WAINGOR
Jul 29 2017 16:09
<3 <3
Gunvant Sarpate
@GunvantSr
Jul 29 2017 16:09
@WAINGOR Cheers! <3
Stephen James
@sjames1958gm
Jul 29 2017 16:09
@WAINGOR :+1:
Gunvant Sarpate
@GunvantSr
Jul 29 2017 16:09
This is the best thing i read today @WAINGOR
Stephen James
@sjames1958gm
Jul 29 2017 16:09
@abhinav-thinktank I believe that the proxy adds the headers to the response that the browser desires
WAINGOR
@WAINGOR
Jul 29 2017 16:10
@GunvantSr good vibes then :) are you also doing FCC excercises now?
Pieter Stokkink
@forkerino
Jul 29 2017 16:10
@WAINGOR :pray:
Darth Skywalker
@AdiSkywalker
Jul 29 2017 16:11

@abhinav-thinktank

The way to tackle cross origin requests is either, as @sjames1958gm said, have a contract between you and a server
OR
using JSONP... as :point_up: explained here

Gunvant Sarpate
@GunvantSr
Jul 29 2017 16:11
@WAINGOR yeah! still trying to learn js
WAINGOR
@WAINGOR
Jul 29 2017 16:13
@GunvantSr cool! I must say: I use the vanilla JS stuff I learned here on a daily basis in Node and at my job... So awesome. And I havent even finished intermediate algo challenges yet :)
Darth Skywalker
@AdiSkywalker
Jul 29 2017 16:13
@WAINGOR Happy for you mate!
Keep it up
Gunvant Sarpate
@GunvantSr
Jul 29 2017 16:14
What's Vanilla JS??
WAINGOR
@WAINGOR
Jul 29 2017 16:14
@AdiSkywalker thanks bro
CamperBot
@camperbot
Jul 29 2017 16:14
waingor sends brownie points to @adiskywalker :sparkles: :thumbsup: :sparkles:
:cookie: 275 | @adiskywalker |http://www.freecodecamp.com/adiskywalker
Darth Skywalker
@AdiSkywalker
Jul 29 2017 16:14
@GunvantSr Pure JS
WAINGOR
@WAINGOR
Jul 29 2017 16:14
@GunvantSr vanilla JS is just plain JS
no frameworks
Darth Skywalker
@AdiSkywalker
Jul 29 2017 16:14
@GunvantSr the code you posted here earlier was in vanilla js
WAINGOR
@WAINGOR
Jul 29 2017 16:15
just old dirty Javascript :D
true
Abhinav Mishra
@abhinav-m
Jul 29 2017 16:15
@AdiSkywalker im wondering how that example works
Gunvant Sarpate
@GunvantSr
Jul 29 2017 16:15
Got it! :)
Darth Skywalker
@AdiSkywalker
Jul 29 2017 16:15
so people who use js framework are fetishists? (they are in a way) :laughing:
@abhinav-thinktank Give it a try!
Abhinav Mishra
@abhinav-m
Jul 29 2017 16:15
So it's not possible to actually create an xmlhttprequest object to make a cross domain request
i mean, you can , but it won't work
the server decides whether it wants to serve these requests or not
Darth Skywalker
@AdiSkywalker
Jul 29 2017 16:16
@abhinav-thinktank It is possible to make XMLHttpRequests, as long as you have a contract with the server on headers you are going to send and receive
Yes
Abhinav Mishra
@abhinav-m
Jul 29 2017 16:16
i see.
so what you've shown me with the script stuff, thats probably close to how jquery does it?
Darth Skywalker
@AdiSkywalker
Jul 29 2017 16:17
It's the most minimal JSONP implementation
which works when contract is not present
it works as long as you are allowed to access requested resourse
whatever is accessible with normal http request (not xmlhttprequest) is accessible with JSONP
Abhinav Mishra
@abhinav-m
Jul 29 2017 16:20
@AdiSkywalker @sjames1958gm thanks! I'll look into this more.
CamperBot
@camperbot
Jul 29 2017 16:20
abhinav-thinktank sends brownie points to @adiskywalker and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: abhinav-thinktank already gave adiskywalker points
:star2: 8188 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Darth Skywalker
@AdiSkywalker
Jul 29 2017 16:20
@abhinav-thinktank :+1:
WAINGOR
@WAINGOR
Jul 29 2017 16:41
Hi all, does anybody how to do this regex propery? Mine logs null :( I just wanna cut out anything except for numbers
var price = '€ 89,95';
var regexPrice = /^\d+$/;
var numberPrice = price.match(regexPrice);
console.log(numberPrice);
Kelechi Chinaka
@ke1echi
Jul 29 2017 16:43
/[0-9]/ @WAINGOR
/[^0-9]/ @WAINGOR
WAINGOR
@WAINGOR
Jul 29 2017 16:44
thanks @kelechy I need to leave out the last / :D
CamperBot
@camperbot
Jul 29 2017 16:44
waingor sends brownie points to @kelechy :sparkles: :thumbsup: :sparkles:
:cookie: 293 | @kelechy |http://www.freecodecamp.com/kelechy
WAINGOR
@WAINGOR
Jul 29 2017 16:44
then it works
Corentin Whyte
@CorySW
Jul 29 2017 17:08
I'm getting really annoyed with this tic tac toe project, It doesn't switch
Stephen James
@sjames1958gm
Jul 29 2017 17:35
@CorySW Share?
Corentin Whyte
@CorySW
Jul 29 2017 17:39
$(".AskO").on("click", function() {
   $(".game").on("click", function() {
      $(this).html("O");
      toggle *=1;
      while(toggle === 1){
         $(".game").on("click", function() {
      $(this).html("X");
      });
      }
   });
Stephen James
@sjames1958gm
Jul 29 2017 17:41
@CorySW You don't want to be adding more click handlers to the .game class
@CorySW I think the person suggested *= -1 as a toggle, because *= 1 isn't going to do anything.
Corentin Whyte
@CorySW
Jul 29 2017 17:42
okay
Stephen James
@sjames1958gm
Jul 29 2017 17:43
$(".game").on("click", function() {
       if (toggle > 0) {
         $(this).html("O");
      } else {
         $(this).html("X");
     }
      toggle *= -1;
      });
Initialize toggle to 1 for O
Moisés Man
@moigithub
Jul 29 2017 18:10
u could also use a boolean flag... instead a number
and switch toggle using NOT operator
toggle = !toggle
Corentin Whyte
@CorySW
Jul 29 2017 18:15
now it works more or less just the AI to do and that's it :+1:
Thayyeb salim
@Thayyebsalim
Jul 29 2017 18:20
I want to know if it works properly
Christopher McCormack
@cmccormack
Jul 29 2017 18:22
@Thayyebsalim seems to work well, although you could improve the style a bit
Thayyeb salim
@Thayyebsalim
Jul 29 2017 18:23
Yeah I'm very bad at styling things
could you share some ideas with me
Christopher McCormack
@cmccormack
Jul 29 2017 18:25
@Thayyebsalim well you have a white background around your logo and search inputs, maybe put your responses within that container instead of below.
@Thayyebsalim your hover background colors on the buttons seem odd as well - not sure why the two buttons have opposite styling
Just moving your results div up a line and changing the font color to black significantly improves the appearance.
Thayyeb salim
@Thayyebsalim
Jul 29 2017 18:31
Ok I will do that
Christopher McCormack
@cmccormack
Jul 29 2017 18:34
@Thayyebsalim maybe consider using a container for the upper section as well - move your search bar and buttons into their own rows, and put the buttons into columns, removing any of the margin/padding CSS you're currently using. This will allow the buttons to use responsive design. I forked your project to show an example:
https://codepen.io/cmccormack/pen/zdropQ
Thayyeb salim
@Thayyebsalim
Jul 29 2017 18:35
I was on it
I just made the changes
thanks @cmccormack
CamperBot
@camperbot
Jul 29 2017 18:37
thayyebsalim sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1074 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Jul 29 2017 18:39
@Thayyebsalim np
Joseph
@revisualize
Jul 29 2017 18:43
Hello
Guderian Raborg
@hypercuber
Jul 29 2017 19:27
How can I use color as a parameter here:

let canvas = document.querySelector('canvas');

canvas.width = 450;
canvas.height = 450;

let c = canvas.getContext('2d');

function DrawRect(x, y, col) {
  c.beginPath();
  c.lineWidth="5";
  c.strokeStyle="black";
  c.rect(x, y, 50, 50);
  c.fillStyle = col;
  c.fill();
  c.stroke();
}

new DrawRect(150, 150, blue);
Pethaf
@Pethaf
Jul 29 2017 19:29
function DrawRect(x,y, col="black") { ... c.strokeStyle=col ...}
And then call DrawRect(... "blue")
CallMeOrange
@EgnaroDev
Jul 29 2017 19:32
Hey guys I managed to solve Wherefore art thou but I don't think I'm supposed to solve like this way
function whatIsInAName(collection, source) {
  return collection.filter(function(Obj) {
    if (Object.keys(source).length < 2)
      return Obj[Object.keys(source)[0]] === source[Object.keys(source)[0]];
    else return Obj[Object.keys(source)[1]] === source[Object.keys(source)[1]];
  });
}
I tried to use i before this
Guderian Raborg
@hypercuber
Jul 29 2017 19:36
@Pethaf Thanks. This works:
new DrawRect(150, 150, 'blue');
CamperBot
@camperbot
Jul 29 2017 19:36
hypercuber sends brownie points to @pethaf :sparkles: :thumbsup: :sparkles:
:cookie: 378 | @pethaf |http://www.freecodecamp.com/pethaf
telepylus
@telepylus
Jul 29 2017 19:37
Hey guys, stuck on the parseInt() with radix... my code is as follows:
function convertToInteger(str, radix) {
var a = parseInt(str, radix); 
  return parseInt();
}

convertToInteger("10011", 9);
Any ideas?
CallMeOrange
@EgnaroDev
Jul 29 2017 19:38
What are you trying to do?
Is this codewars?
telepylus
@telepylus
Jul 29 2017 19:39
Use parseInt() in the convertToInteger function so it converts a binary number to an integer and returns it.
korzo
@korzo
Jul 29 2017 19:39
@telepylus you should return a
CallMeOrange
@EgnaroDev
Jul 29 2017 19:39
oh so 10011 is 9
Yeah, parseInt() does nothing...
I never heard of using two numbers in parseInt(), so not sure I know what you are doing
telepylus
@telepylus
Jul 29 2017 19:41
Okay, thanks for your help
CallMeOrange
@EgnaroDev
Jul 29 2017 19:41
@telepylus Is this a challenge from codewars?
telepylus
@telepylus
Jul 29 2017 19:42
No, it is a challenge from Basic JS in beta FCC
CallMeOrange
@EgnaroDev
Jul 29 2017 19:42
I see
telepylus
@telepylus
Jul 29 2017 19:42
I am a bit lost on parseInt(), I don't know what it is supposed to do
CallMeOrange
@EgnaroDev
Jul 29 2017 19:42
@telepylus parseInt("5") // 5
Well not to convert a string to number but it convert anything to an integer
Moisés Man
@moigithub
Jul 29 2017 19:43
if 101101 is a binary num..then u need to use 2 as radix
telepylus
@telepylus
Jul 29 2017 19:43
Okay, but what does the radix do?
Christopher McCormack
@cmccormack
Jul 29 2017 19:43
@telepylus I think you just need to return a
CallMeOrange
@EgnaroDev
Jul 29 2017 19:43
do you know binary?
Moisés Man
@moigithub
Jul 29 2017 19:43
binary only use 0 and 1 (2 digits)
CallMeOrange
@EgnaroDev
Jul 29 2017 19:43
^
I forgot how to read binary but in this challenge 10011 is 9? if so , maybe just replace it?
telepylus
@telepylus
Jul 29 2017 19:44
function convertToInteger(str, radix) {
var a = parseInt(str, radix); 
  return a;
}

convertToInteger("10011", 2);
Still not working.
Moisés Man
@moigithub
Jul 29 2017 19:45
CallMeOrange
@EgnaroDev
Jul 29 2017 19:45
^ I use it a lot
korzo
@korzo
Jul 29 2017 19:45
@EgnaroDev You have to iterate all keys in source
CallMeOrange
@EgnaroDev
Jul 29 2017 19:45
Yeah thats what I tried to do before
I had two ways to do it but was a failure
function whatIsInAName(collection, source) {
  return collection.filter(function(Obj, i) {
    for (var j = 0; j < Object.keys(source).length; j++){
      return Obj[Object.keys(source)[i]] === source[Object.keys(source)[j]];
    }
  });
}
telepylus
@telepylus
Jul 29 2017 19:46
Okay, when I am testing it, I am getting the right answer
Moisés Man
@moigithub
Jul 29 2017 19:46
return exit the function.. having it inside a for/loop will make it...
CallMeOrange
@EgnaroDev
Jul 29 2017 19:46
maybe because return halt loop
Moisés Man
@moigithub
Jul 29 2017 19:46
yep
Christopher McCormack
@cmccormack
Jul 29 2017 19:46
@EgnaroDev 1001 should be 9
CallMeOrange
@EgnaroDev
Jul 29 2017 19:46
I see
korzo
@korzo
Jul 29 2017 19:47
@EgnaroDev You have to return false, if comparison fails or return true at the end of the loop
CallMeOrange
@EgnaroDev
Jul 29 2017 19:48
return exit the function.. having it inside a for/loop will make it...
What do you mean by that?
telepylus
@telepylus
Jul 29 2017 19:48
Okay, I am getting the correct answer in repl.it for my code, it is returning 19, but the challenge is saying that it is incorrect. Any ideas? I tried refreshing it, because sometimes FCC is glitchy, but still wrong
Moisés Man
@moigithub
Jul 29 2017 19:48

maybe because return halt loop

u completed the phrase before me.. so i didnt have to
"iterate only once"

CallMeOrange
@EgnaroDev
Jul 29 2017 19:49
oh
Christopher McCormack
@cmccormack
Jul 29 2017 19:50
@telepylus what's the exercise name?
CallMeOrange
@EgnaroDev
Jul 29 2017 19:50
Okay I'll try to do something but can I solve this only .filter() only? or do I need a for loop
telepylus
@telepylus
Jul 29 2017 19:50
Basic JavaScript: Use the parseInt Function with a Radix
Would there be a glitch in the exercise maybe?
Jor
@joreyesl
Jul 29 2017 19:51
@telepylus the challenge gave you function convertToInteger(str) they won't pass in the radix as an argument. You just need to hard code it inside the function.
Christopher McCormack
@cmccormack
Jul 29 2017 19:51
@telepylus your test shouldn't have a second argument
and your function should only have one parameter
CallMeOrange
@EgnaroDev
Jul 29 2017 19:52
so you should to convert binary to integer for this challenge?
korzo
@korzo
Jul 29 2017 19:52
@EgnaroDev If comparison fails, you return false and it will remove current element from array
telepylus
@telepylus
Jul 29 2017 19:52
Ah okay, so remove the second argument?
Christopher McCormack
@cmccormack
Jul 29 2017 19:52
correct, the radix is an implied 2
CallMeOrange
@EgnaroDev
Jul 29 2017 19:52
@korzo Yeah, I know how .filter() work
telepylus
@telepylus
Jul 29 2017 19:53
Ah brilliant. So, technically, I could do it the way I was doing it but for the purpose of the challenge it is reading it as an error?
Christopher McCormack
@cmccormack
Jul 29 2017 19:54
@telepylus if you wanted to make a general purpose function, sure, but then you're just recreating parseInt anyhow
korzo
@korzo
Jul 29 2017 19:54
@EgnaroDev In your last snippet you posted, you compare only first key
telepylus
@telepylus
Jul 29 2017 19:54
@cmccormack thanks!
CamperBot
@camperbot
Jul 29 2017 19:54
telepylus sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1075 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Jul 29 2017 19:54
@telepylus np. This is in Beta correct?
telepylus
@telepylus
Jul 29 2017 19:55
Yes, the beta
I didn't come across it in the regular, I don't think
CallMeOrange
@EgnaroDev
Jul 29 2017 19:55
@korzo But I created if statements to compare different keys depending on source's length
Christopher McCormack
@cmccormack
Jul 29 2017 19:55
that's why I asked, didn't find it until I searched the beta
gotta let us know that so we can check our own answers :)
CallMeOrange
@EgnaroDev
Jul 29 2017 19:57
Sorry, we were talking about wrong snippet
Moisés Man
@moigithub
Jul 29 2017 19:57
sources might contains mora than 1 value.. soo u should keep values ONLY if ALL key:properties match @EgnaroDev
its possible with a loop.. but u will need a extra flag.. and only return true if ALL keys:values are present
if u want a easier way.. u could use .every array method or do both as practice
CallMeOrange
@EgnaroDev
Jul 29 2017 19:58
Obj[Object.keys(source)] === source[Object.keys(source)[i]];
Nvm, not what I expected
Moisés Man
@moigithub
Jul 29 2017 19:59
cuz .keys return an array
CallMeOrange
@EgnaroDev
Jul 29 2017 20:00
Yeah
Object.keys(source) == ['last', 'first'] for example
Moisés Man
@moigithub
Jul 29 2017 20:00
yep
CallMeOrange
@EgnaroDev
Jul 29 2017 20:00
I have console.logged everything :p
just a question.. if I have this code
return collection.filter(function(Obj, i) {
      return Obj[Object.keys(source)[i]] === source[Object.keys(source)[i]];
  });
How would I return else where I can not halt loop?
Moisés Man
@moigithub
Jul 29 2017 20:04
keys.. return an array
but u using the collection index (a different array)
if both arrays have diff lengths.. then u might access unexistant elements
collection = [1,2,3,4,5,6]
sourceKeys = [9,8]
for (var i = 0 ; i<collection.length ; i++){
     console.log( sourceKeys[i]  );
}
as example
CallMeOrange
@EgnaroDev
Jul 29 2017 20:05
Well I thought its okay if I accessed not existed elements (undefined)
so its better to do this way like before?
function whatIsInAName(collection, source) {
  return collection.filter(function(Obj, i) {
    for (var j = 0; j < Object.keys(source).length; j++){
      return Obj[Object.keys(source)[i]] === source[Object.keys(source)[j]];
    }
  });
}
I know return halt loop but something like that
korzo
@korzo
Jul 29 2017 20:07
@EgnaroDev You are still comparing only first key
CallMeOrange
@EgnaroDev
Jul 29 2017 20:07
I know because of return...
Moisés Man
@moigithub
Jul 29 2017 20:07
as posted above.. u need extra flag on ur checking
before return some value
and only return after u check all ur source keys
CallMeOrange
@EgnaroDev
Jul 29 2017 20:07
I don't understand what you mean by flag
Moisés Man
@moigithub
Jul 29 2017 20:07
flag = variable
korzo
@korzo
Jul 29 2017 20:08
@EgnaroDev compare with !== and return false
and return true after loop
CallMeOrange
@EgnaroDev
Jul 29 2017 20:08
ah thats what I was thinking too
Moisés Man
@moigithub
Jul 29 2017 20:08
var allOK = true;
for (...){
   if( not exist ) allOK = false;
}
return allOK;
CallMeOrange
@EgnaroDev
Jul 29 2017 20:09
But shouldn't I console.log first? to see if everything go well then do similar like that example
Moisés Man
@moigithub
Jul 29 2017 20:10
or like @korzo saying.. returning earlier
for (...){
      if ( not exist) return false
}
return true;
CallMeOrange
@EgnaroDev
Jul 29 2017 20:10
Yeah I have done something like that before
I'll try
Right now I want to console.log...
console.log(Obj[Object.keys(source)[i]] === source[Object.keys(source)[i]]); I get true false true which should be false false true for this case whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "c": 2 });
Moisés Man
@moigithub
Jul 29 2017 20:13
show code
CallMeOrange
@EgnaroDev
Jul 29 2017 20:14
function whatIsInAName(collection, source) {
  return collection.filter(function(Obj, i) {
      console.log(Obj[Object.keys(source)[i]] === source[Object.keys(source)[i]]);
  });
}
Pretty much the same
Moisés Man
@moigithub
Jul 29 2017 20:14
u need cnditions and a loop like the example
CallMeOrange
@EgnaroDev
Jul 29 2017 20:14
Fine :/ Forget console.log
with .filter() right?
I thought maybe you can do like that example without .filter()
Moisés Man
@moigithub
Jul 29 2017 20:16
ofc u can do without filter.. code will be longer, extra loop extra variable
CallMeOrange
@EgnaroDev
Jul 29 2017 20:16
Yeah you're right
CallMeOrange
@EgnaroDev
Jul 29 2017 20:21
Now I know why I got true false true because { "a": 1, "b": 2 } and { "a": 1, "b": 2, "c": 2 } had the same value
I should be doing something like this console.log(collection[i].hasOwnProperty(Object.keys(source)[1])) instead of console.log(collection[i][Object.keys(source)[i]] === source[Object.keys(source)[i]]);
First one would be easier to compare keys/values
Ronique Ricketts
@RoniqueRicketts
Jul 29 2017 20:32
return React.createElement('div', {className: 'shopping-list'},
  React.createElement('h1', /* ... h1 children ... */),
  React.createElement('ul', /* ... ul children ... */)
);
Is className the same as class="shopping-list"
korzo
@korzo
Jul 29 2017 20:34
@EgnaroDev
function whatIsInAName(collection, source) {
  return collection.filter(function(Obj, i) {
      // loop over source keys
      // if current source key !== Obj key return false
     // end loop
     // return true
  });
}
Moisés Man
@moigithub
Jul 29 2017 20:35
yes @RoniqueRicketts
className will translate to class when the html gets rendered
Ronique Ricketts
@RoniqueRicketts
Jul 29 2017 20:37
@moigithub thanks man. Noobie question. Because I am just learning it starting today. :)
CamperBot
@camperbot
Jul 29 2017 20:37
roniquericketts sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3543 | @moigithub |http://www.freecodecamp.com/moigithub
CallMeOrange
@EgnaroDev
Jul 29 2017 20:40
@korzo Yeah, this is what I did
function whatIsInAName(collection, source) {
  return collection.filter(function(Obj){
  for (var i = 0; i < collection.length; i++){
    if (!Obj.hasOwnProperty(Object.keys(source)[1])) return false;
  }
  return true;
  });
}
I tried !Obj.hasOwnProperty(Object.keys(source)[i]) but I get empty array.. if I do console.log() all return false
korzo
@korzo
Jul 29 2017 20:41
@EgnaroDev use for .. in loop
also you loop over collection instead of source
CallMeOrange
@EgnaroDev
Jul 29 2017 20:42
Not .hasOwnProperty?
Do I have to do "that" instead of .hasOwnProperty? to compare key's values
Ronique Ricketts
@RoniqueRicketts
Jul 29 2017 20:43
@moigithub so an idName can be set the same way?
korzo
@korzo
Jul 29 2017 20:43
@EgnaroDev hasOwnProperty only verify, if property is on object and not in prototype chain
CallMeOrange
@EgnaroDev
Jul 29 2017 20:44
Yeah, why wouldn't i work?
Stephen James
@sjames1958gm
Jul 29 2017 20:44
@EgnaroDev Create a variable assigned to Object.keys(source) and make that your inner loop.
You are already looping on collection with .filter
Moisés Man
@moigithub
Jul 29 2017 20:48
{id: 'myId'}
className is a "special" case cuz class is a javascript es6 reserved word to create classes @RoniqueRicketts so to avoid conflict they named it className
CallMeOrange
@EgnaroDev
Jul 29 2017 20:49
@sjames1958gm What would happen if I use Object.keys(source) instead?
Stephen James
@sjames1958gm
Jul 29 2017 20:50
@EgnaroDev You need to validate that each Obj has all the keys/value from source.
Using the array Object.keys(source) and a loop is one way.
Ronique Ricketts
@RoniqueRicketts
Jul 29 2017 20:51
Oh for real, idk how I missed that @moigithub forgot that it is reserved.
CallMeOrange
@EgnaroDev
Jul 29 2017 20:51
return collection.filter(function(Obj){
  for (var i = 0; i < collection.length; i++){
    var sourceObj = Object.keys(source);
   console.log(Obj.hasOwnProperty(sourceObj[i]));
  }
  //return true;
  });
korzo
@korzo
Jul 29 2017 20:52
@EgnaroDev Why collection.length?
you have to loop source keys
as I wrote earlier, use for .. in loop
CallMeOrange
@EgnaroDev
Jul 29 2017 20:53
@korzo Relax.. I already changed it to sourceObj.length
function whatIsInAName(collection, source) {
  return collection.filter(function(Obj){
    var sourceObj = Object.keys(source);
  for (var i = 0; i < sourceObj.length; i++){
   if (!Obj.hasOwnProperty(sourceObj[i])) return false;
  }
  return true;
  });
}
I'll use for .. in loop now
I just didn't know what to use for until sjames told me to create a variable for Object.keys(source)
Stephen James
@sjames1958gm
Jul 29 2017 20:56
@EgnaroDev for .. in over source will give similar results. You aren't verifying that source / Obj have the same value for the key.
CallMeOrange
@EgnaroDev
Jul 29 2017 20:57
Isn't that why I should use .hasOwnProperty instead?
ah I see what you mean, I misunderstood how .hasOwnProperty works
thought it would be like Object.hasOwnProperty(value) instead of a key
CallMeOrange
@EgnaroDev
Jul 29 2017 21:03
@sjames1958gm @korzo well there you go, all because I misunderstood how .hasOwnProperty worked..
function whatIsInAName(collection, source) {
  return collection.filter(function(Obj){
    var sourceObj = Object.keys(source);
  for (var i = 0; i < sourceObj.length; i++){
   if (Obj[sourceObj[i]] !== source[sourceObj[i]]) return false;
  }
  return true;
  });
}
@sjames1958gm @korzo thanks, I'm going to work on it without .filter()
CamperBot
@camperbot
Jul 29 2017 21:04
egnarodev sends brownie points to @sjames1958gm and @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 312 | @korzo |http://www.freecodecamp.com/korzo
:star2: 8189 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 29 2017 21:05
@EgnaroDev :+1: .filter is the more modern way to do it - Consider .every for your inner loop
CallMeOrange
@EgnaroDev
Jul 29 2017 21:05
Sure
function whatIsInAName(collection, source) {
  return collection.filter(function(Obj){
  for (var i = 0; i < Object.keys(source).length; i++){
   if (Obj[Object.keys(source)[i]] !== source[Object.keys(source)[i]]) return false;
  }
  return true;
  });
}
A little better I guess
Might be hard to read but shorter
Stephen James
@sjames1958gm
Jul 29 2017 21:15
@EgnaroDev Better to move Object.keys outside of loops
  var keys = Object.keys(source);
  return collection.filter(function(item) {
    return keys.every(function(key) {
      return item[key] === source[key];
    });
  });
CallMeOrange
@EgnaroDev
Jul 29 2017 21:26
@sjames1958gm just curious, why?
Stephen James
@sjames1958gm
Jul 29 2017 21:28
Depending on the size of source it could be an expensive operation to do inside the loops
CallMeOrange
@EgnaroDev
Jul 29 2017 21:29
Hm..
@sjames1958gm sorry but could you help me with this?
function whatIsInAName(collection, source) {
  var answer = true;
  for (var i = 0; i < collection.length; i++){
   if (collection[Object.keys(source)[i]] !== source[Object.keys(source)[i]]) answer = false;
  }
  return answer;
}
Not sure what to do with a for loop
Oops, missed something
collection[i][Object.keys(source)[i]] !== source[Object.keys(source)[i]]
Stephen James
@sjames1958gm
Jul 29 2017 21:30
@EgnaroDev You are using the collection loop variable on the source keys array.
If you want to do like filter you need to push onto a result array when answer is not false
you will still need two loops
CallMeOrange
@EgnaroDev
Jul 29 2017 21:31
I see
So both loop for both parameters?
Nested loop
Stephen James
@sjames1958gm
Jul 29 2017 21:32
yes
filter is really a loop, so you had nested loops before
CallMeOrange
@EgnaroDev
Jul 29 2017 21:34
Yeah
Just want to do it without .filter()
function whatIsInAName(collection, source) {
  var arr = [];
  for (var i = 0; i < collection.length; i++){
   for (var j = 0; j < Object.keys(source); j++){
   }
   console.log(collection[i][Object.keys(source)[j]] !== source[Object.keys(source)[i]]);
  }
}
Why am I getting false true true when it should be false false true?
Stephen James
@sjames1958gm
Jul 29 2017 21:36
understand
CallMeOrange
@EgnaroDev
Jul 29 2017 21:37
console.log(collection[i][Object.keys(source)[j]] !== source[Object.keys(source)[j]]);
Stephen James
@sjames1958gm
Jul 29 2017 21:37
That's it
CallMeOrange
@EgnaroDev
Jul 29 2017 21:37
Yeah same value..
Stephen James
@sjames1958gm
Jul 29 2017 21:37
your console.log is not inside the inner loop
CallMeOrange
@EgnaroDev
Jul 29 2017 21:38
oh my bad
Moisés Man
@moigithub
Jul 29 2017 21:38
inner loop condition is wrong
Kelechi Chinaka
@ke1echi
Jul 29 2017 21:40
element[0].toUpperCase() + element.slice(1)
Obama expected output
what am i doing wrong
Moisés Man
@moigithub
Jul 29 2017 21:41
whats element ?
CallMeOrange
@EgnaroDev
Jul 29 2017 21:41
Sorry, I'm bad with nested loop :/
Kelechi Chinaka
@ke1echi
Jul 29 2017 21:41
string
Moisés Man
@moigithub
Jul 29 2017 21:41
element = "hello"
element[0].toUpperCase() + element.slice(1)
//"Hello"
works fine
Stephen James
@sjames1958gm
Jul 29 2017 21:42
@moigithub Are you assigning that to something?
Moisés Man
@moigithub
Jul 29 2017 21:42
if u not sure.. test ur code on devtools/console.. or use repl.it @kelechy
CallMeOrange
@EgnaroDev
Jul 29 2017 21:42
missing variable keyword?
or a parameter maybe
Moisés Man
@moigithub
Jul 29 2017 21:42
@sjames1958gm nope.. just a test
CallMeOrange
@EgnaroDev
Jul 29 2017 21:43
ugh I found out what I was doing wrong..
j < Object.keys(source)
Moisés Man
@moigithub
Jul 29 2017 21:43
:point_up: 29 de julio de 2017 16:38 @EgnaroDev
CallMeOrange
@EgnaroDev
Jul 29 2017 21:44
I didn't know what you mean by that
Stephen James
@sjames1958gm
Jul 29 2017 21:44
@moigithub Oops I meant @kelechy are you assigning that result
CallMeOrange
@EgnaroDev
Jul 29 2017 21:44
Never mind
but I do
function whatIsInAName(collection, source) {
  var arr = [];
  for (var i = 0; i < collection.length; i++){
   for (var j = 0; j < Object.keys(source).length; j++){
   console.log(collection[i][Object.keys(source)[j]] === source[Object.keys(source)[j]]);
  }
  }
}
Idowu Wasiu
@Hoxtygen
Jul 29 2017 21:54
Help needed here on recursion
Anybody home?
Stephen James
@sjames1958gm
Jul 29 2017 21:55
sure
CallMeOrange
@EgnaroDev
Jul 29 2017 21:56
@sjames1958gm so you stick with your currently profile picture? you seems stop changing it lately
Stephen James
@sjames1958gm
Jul 29 2017 21:56
@EgnaroDev being lazy
Idowu Wasiu
@Hoxtygen
Jul 29 2017 21:56
@sjames1958gm mind helping out to explain recursion? hard to understand for now
CallMeOrange
@EgnaroDev
Jul 29 2017 21:56
:/
Stephen James
@sjames1958gm
Jul 29 2017 21:57
@Hoxtygen Sure
Idowu Wasiu
@Hoxtygen
Jul 29 2017 21:57
@sjames1958gm thanks ... here we go
CamperBot
@camperbot
Jul 29 2017 21:57
hoxtygen sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8190 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Idowu Wasiu
@Hoxtygen
Jul 29 2017 21:59

@sjames1958gm here's a function for finding greatest common denominator recursively, explain pls
``

function gcd(a, b) {
// body...
if (b === 0) {
return a;
} else {
return gcd(b, a % b);
}

}
``

CallMeOrange
@EgnaroDev
Jul 29 2017 22:00
Has to be 3 backticks
Idowu Wasiu
@Hoxtygen
Jul 29 2017 22:00
@EgnaroDev okay, been a long time i visited
CallMeOrange
@EgnaroDev
Jul 29 2017 22:00
I'll teach you a trick
This message was deleted
Idowu Wasiu
@Hoxtygen
Jul 29 2017 22:01

@sjames1958gm whats the b in


gcd(b, a%b)

doing?

Stephen James
@sjames1958gm
Jul 29 2017 22:01
Not sure I can explain all the maths. But the idea behind recursion is to reduce the problem down to a base case.
In this function the base case is b == 0
The gcd of a, 0 is a
if b is not zero then you recurse.
CallMeOrange
@EgnaroDev
Jul 29 2017 22:02
```js
code
```
:(
EgnaroDev @EgnaroDev :walking:
Stephen James
@sjames1958gm
Jul 29 2017 22:04
From wikipedia gcd(a,b)=gcd(b,a mod b)
a mod b is the remainder of a / b
You do this calculation until a mod b is zero that is b divide a evenly
When b divides a evenly then b is the gcd of a and b
Idowu Wasiu
@Hoxtygen
Jul 29 2017 22:05
@sjames1958gm i know modulus. but what if b is greater than a?
Stephen James
@sjames1958gm
Jul 29 2017 22:06
@Hoxtygen when a < b then a mod b is a
so after the first pass then two are swapped and a > b
@Hoxtygen Here is the values of a/b for 25, 10 and 10, 25 the second one takes one more step to reverse a/b
" a: 25, b: 10"
" a: 10, b: 5"
" a: 5, b: 0"
5
" a: 10, b: 25"
" a: 25, b: 10"
" a: 10, b: 5"
" a: 5, b: 0"
5
Idowu Wasiu
@Hoxtygen
Jul 29 2017 22:09
@sjames1958gm how about this?

function gcd(a, b) {
    // body... 
    if (b === 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }

}

console.log(gcd(48, 180));
Stephen James
@sjames1958gm
Jul 29 2017 22:09
" a: 48, b: 180"
" a: 180, b: 48"
" a: 48, b: 36"
" a: 36, b: 12"
" a: 12, b: 0"
12
You might need to email Euclid to find out why this works ;)
Nick Cleary
@Hijerboa
Jul 29 2017 22:11
@sjames1958gm I know I just saw your message now, but it helped a lot with solving the issue. Thanks mate!
CamperBot
@camperbot
Jul 29 2017 22:11
hijerboa sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Idowu Wasiu
@Hoxtygen
Jul 29 2017 22:11
@sjames1958gm the guy still alive?
CamperBot
@camperbot
Jul 29 2017 22:11
:star2: 8191 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
CallMeOrange
@EgnaroDev
Jul 29 2017 22:11
lol
Stephen James
@sjames1958gm
Jul 29 2017 22:11
@Hijerboa :+1:
CallMeOrange
@EgnaroDev
Jul 29 2017 22:11
@Hoxtygen create a ritual to summon him :trollface:
his spiritual, ghost
Stephen James
@sjames1958gm
Jul 29 2017 22:13
@EgnaroDev :ghost:
CallMeOrange
@EgnaroDev
Jul 29 2017 22:13
Oh my god, :runner:
Idowu Wasiu
@Hoxtygen
Jul 29 2017 22:13
@sjames1958gm i'm getting a feel for it, but why do we need to interchange the values?
kumquatfelafel
@kumquatfelafel
Jul 29 2017 22:13
:cactus:
CallMeOrange
@EgnaroDev
Jul 29 2017 22:13
@kumquatfelafel :wave:
kumquatfelafel
@kumquatfelafel
Jul 29 2017 22:14
'ello
Stephen James
@sjames1958gm
Jul 29 2017 22:14
@Hoxtygen I think the interchange is a result of the algorithm, not a need. Because of the a mod b
When b > a they just swap
@Hoxtygen You are stretching my Maths here :smile: :boom:
Idowu Wasiu
@Hoxtygen
Jul 29 2017 22:16
@sjames1958gm how am i suppose to know it if i dont stretch yours?
CallMeOrange
@EgnaroDev
Jul 29 2017 22:17
I guess I have to come back to Roman Numeral Converter... took a break from it for few days
Stephen James
@sjames1958gm
Jul 29 2017 22:18
@Hoxtygen lol
@EgnaroDev A nested looper :)
Take a piece of paper and think about how you would convert the number without code.
CallMeOrange
@EgnaroDev
Jul 29 2017 22:19
Yeah thats what I was doing whole time
White Board :)

  var answer = "";

  //var decValues = number.reverse();
  var values = number.filter(function(element){
      return element <= num;
  }).reverse();
  var array = [];
  for (var i = 0; i < values.length; i++){
    array.push(romanNum[number.indexOf(values[i])]);
  }
  return array;
}
convertToRoman(6);
I was thinking of nested loop too, Maybe one subtract the number (from parameter) then push roman number into an array so on..
Idowu Wasiu
@Hoxtygen
Jul 29 2017 22:20
@sjames1958gm solved the roman numeral converter using array and looping through it
CallMeOrange
@EgnaroDev
Jul 29 2017 22:20
I wonder if my code is in good progress?
Stephen James
@sjames1958gm
Jul 29 2017 22:21
@Hoxtygen :+1:
Idowu Wasiu
@Hoxtygen
Jul 29 2017 22:21
@sjames1958gm do you also do mockups while building a website or is it just me?
Stephen James
@sjames1958gm
Jul 29 2017 22:21
@EgnaroDev Not sure what the filter is for.
kumquatfelafel
@kumquatfelafel
Jul 29 2017 22:22
@EgnaroDev Could you explain what... :point_up:
Stephen James
@sjames1958gm
Jul 29 2017 22:22
@Hoxtygen I should but don't design is my biggest problem. I design like a kindergarten fingerpaints, but with less skill
kumquatfelafel
@kumquatfelafel
Jul 29 2017 22:22
let's say our num is 951. What happens?
Idowu Wasiu
@Hoxtygen
Jul 29 2017 22:22
@EgnaroDev i looked at your code and i'm super confused....
CallMeOrange
@EgnaroDev
Jul 29 2017 22:23
@sjames1958gm say I have an array of 1 to 1000 then use 6 to get less than the number of number, this is hard to explain... but If I have 6 then I get [5, 1]
@kumquatfelafel I guess [900, 50, 1]
I know its not good yet, if I have 2000 then I don't know what to do :/
Idowu Wasiu
@Hoxtygen
Jul 29 2017 22:24
@sjames1958gm you're doing better than me there, had to learn photoshop by fire by force. like i'm still learning using youtube videos....
Stephen James
@sjames1958gm
Jul 29 2017 22:24
@EgnaroDev It that how you would do it by hand?
not something like
while number > 0) 
   if number > 1000) then place M, subtract 1000 from number
   else if number > 990 then place CM, subtract 990 from number 
  . . .
@Hoxtygen You tube is a great resource, if you can find the right channels
CallMeOrange
@EgnaroDev
Jul 29 2017 22:25
Hm.. yours is good example
I thought I have to do something like that with a for loop
Man, @sjames1958gm thanks I think I can do while loop
CamperBot
@camperbot
Jul 29 2017 22:26
egnarodev sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8192 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 29 2017 22:26
FCC puts so much stress on arrays/for loops the poor while loop is left in the dark
CallMeOrange
@EgnaroDev
Jul 29 2017 22:26
lol
Yeah, which is why I forgot how to use while loop often
Stephen James
@sjames1958gm
Jul 29 2017 22:27
Just found a Mifune documentary on Netflix !!
CallMeOrange
@EgnaroDev
Jul 29 2017 22:27
I have to look up then test it somewhere on repl.it
Idowu Wasiu
@Hoxtygen
Jul 29 2017 22:27
@sjames1958gm can't remember using while loops, that guy has got to be angry at coders
Kelechi Chinaka
@ke1echi
Jul 29 2017 22:27
function initials(str){
  return str.split(' ').map((element) => {
    return (element === str[str.length - 1]) ? element[0].toUpperCase() + element.slice(1) : 
    element[0].toUpperCase() + '.'    
  });
}
CallMeOrange
@EgnaroDev
Jul 29 2017 22:28
it looks like you are doing Search and Replace
Kelechi Chinaka
@ke1echi
Jul 29 2017 22:28
i think am missing something @sjames1958gm
Stephen James
@sjames1958gm
Jul 29 2017 22:28
@kelechy What are you trying to do?
Kelechi Chinaka
@ke1echi
Jul 29 2017 22:29
initials('Barack Hussain obama') => returns B.H.Obama
Stephen James
@sjames1958gm
Jul 29 2017 22:29
@kelechy element === str[str.length - 1] one of these is a word and the other a character
str.split(' ').map((element, index, array)
Use index === array.length - 1
CallMeOrange
@EgnaroDev
Jul 29 2017 22:30
@sjames1958gm by nested loop, did you mean for loop and while loop?
Kelechi Chinaka
@ke1echi
Jul 29 2017 22:30
no i splitted the space
Stephen James
@sjames1958gm
Jul 29 2017 22:30
@EgnaroDev yes
Kelechi Chinaka
@ke1echi
Jul 29 2017 22:30
they are both words @sjames1958gm
CallMeOrange
@EgnaroDev
Jul 29 2017 22:30
ah makes sense
Stephen James
@sjames1958gm
Jul 29 2017 22:30
@kelechy but str is still the original string
Kelechi Chinaka
@ke1echi
Jul 29 2017 22:31
yea @sjames1958gm
Stephen James
@sjames1958gm
Jul 29 2017 22:31
@EgnaroDev I used nested loops when I had an array of values for the roman numerals
@kelechy Use the second/third parameter passed to the filter function
CallMeOrange
@EgnaroDev
Jul 29 2017 22:32
okay, I'm going to plan my logic on white board
:wave:
Kelechi Chinaka
@ke1echi
Jul 29 2017 22:32
white? @EgnaroDev
CallMeOrange
@EgnaroDev
Jul 29 2017 22:32
I meant, dry erase board
Kelechi Chinaka
@ke1echi
Jul 29 2017 22:33
gl
CallMeOrange
@EgnaroDev
Jul 29 2017 22:33
You know a board where you can write on it then erase it
thanks
:runner:
Stephen James
@sjames1958gm
Jul 29 2017 22:36
:white_medium_square:
Kelechi Chinaka
@ke1echi
Jul 29 2017 22:37
why not your computer @EgnaroDev
kumquatfelafel
@kumquatfelafel
Jul 29 2017 22:37
@sjames1958gm It won't toggle when I click it! What is happening?!?!? :o
Stephen James
@sjames1958gm
Jul 29 2017 22:37
@kumquatfelafel Click Harder!
Kelechi Chinaka
@ke1echi
Jul 29 2017 22:37
i am missing something little, i would check it out @sjames1958gm
kumquatfelafel
@kumquatfelafel
Jul 29 2017 22:38
@sjames1958gm It doesn't seem to be working. Maybe I'm just not clicking fast enough.
Kelechi Chinaka
@ke1echi
Jul 29 2017 22:38
lol..maybe the keypad is bad @kumquatfelafel
Stephen James
@sjames1958gm
Jul 29 2017 22:38
Since you are using chaining, you need to use the index/array passed to the filter function
To get the result of the split(' ')
Stephen James
@sjames1958gm
Jul 29 2017 22:50
@kelechy
  return str.split(' ').map((element, index, array) => {
    return element[0].toUpperCase() + (index === array.length - 1) ? element.slice(1) :  '.'    
  });
CallMeOrange
@EgnaroDev
Jul 29 2017 22:52
@kelechy well it would be easier to work on it and add ideas etc., if I became stuck I can go back
For example I don't know how to create a for loop and an array with values 0 to 5. I would go on board to write Create a loop that iterates start by 0 then stop by less than 6, push these values into an array
CallMeOrange
@EgnaroDev
Jul 29 2017 22:58
Its harder to create a logic for Roman Numeral Converter by thinking about it alone
Kelechi Chinaka
@ke1echi
Jul 29 2017 22:59
nice..you know i barely use those extra map parameters @sjames1958gm
thats true @EgnaroDev
kumquatfelafel
@kumquatfelafel
Jul 29 2017 23:10

So, kinda generalized question.
Suppose I'm working with a for loop where both distance from beginning and end are important.
Do you think it's better to have...

for(var i = arr.length - 1, j = 0; i >= 0; i--, j++) {
   blah(i);
   blah(j);
}

or

for(var i = arr.length - 1; i >= 0; i--) {
   blah(i);
   blah(arr.length - 1 - i);
}

I feel there are some benefits to each. Though I kinda prefer clean for loop body?

CallMeOrange
@EgnaroDev
Jul 29 2017 23:11
is blah defined??
Nick Cleary
@Hijerboa
Jul 29 2017 23:12
@EgnaroDev Asking the real questions
kumquatfelafel
@kumquatfelafel
Jul 29 2017 23:12
blah is overloaded and more. It could be anything you want it to be~ :o
Jim Tryon
@jimtryon
Jul 29 2017 23:12
How do you return an array of values from an object? I tried the following
function values(dict) {
    return Object.values(dict);
}
That is from MDN documentation
CallMeOrange
@EgnaroDev
Jul 29 2017 23:12
about @Hijerboa
CamperBot
@camperbot
Jul 29 2017 23:12
:cookie: 269 | @hijerboa |http://www.freecodecamp.com/hijerboa
CallMeOrange
@EgnaroDev
Jul 29 2017 23:13
@kumquatfelafel oh you got me confused lol, I thought blah was a variable but I guess you mean it as console.log
kumquatfelafel
@kumquatfelafel
Jul 29 2017 23:14

@jimtryon That can work, but I think it's also a relatively new function, and depending on browser/where it's being used... might also not work.

If it says something along the lines of "this is not a function" then it means it isn't supported.

Jim Tryon
@jimtryon
Jul 29 2017 23:14
So this is the challenge

Define a function named values that has the following parameter:

dict - an object
Return an array containing the values of the object.

Stephen James
@sjames1958gm
Jul 29 2017 23:28
@jimtryon You can do Object.keys().map
Moisés Man
@moigithub
Jul 29 2017 23:28
es7 Object.values ? (or was 8)
Stephen James
@sjames1958gm
Jul 29 2017 23:28
Object.keys(dict).map(e => dict[e]);
@jimtryon I wouild assume they don't want you to use Object.values
kumquatfelafel
@kumquatfelafel
Jul 29 2017 23:30
@moigithub I think issue is either browser/site doesn't support or as @sjames1958gm points out, they may not want to use Object.values, and fail for doing so.
Moisés Man
@moigithub
Jul 29 2017 23:31
babel transpile or polyfill :P
John
@AnonymousLords
Jul 29 2017 23:40
:point_up: July 28, 2017 11:18 PM Wow thanks @kumquatfelafel It worked! 12 lines of coding down to 7. (I compacted the return true/ false statement)
CamperBot
@camperbot
Jul 29 2017 23:40
:cookie: 553 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
anonymouslords sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
John
@AnonymousLords
Jul 29 2017 23:40

function palindrome(str) {
str = str.toLowerCase().replace(/[^0-9a-z]/g, "");
var rev = str;
var array = str.split('').reverse().join('');
if (rev == array) {
  return true;} else return false;}
kumquatfelafel
@kumquatfelafel
Jul 29 2017 23:42
@AnonymousLords So you generally won't compact your if else statements like that.
John
@AnonymousLords
Jul 29 2017 23:43
Yes, but it is easier to read in my eyes :P You can see what it will return vs what it wont all in one line.
Could it affect my code later on?
kumquatfelafel
@kumquatfelafel
Jul 29 2017 23:43
function palindrome(str) {
str = str.toLowerCase().replace(/[^0-9a-z]/g, "");
var rev = str.split('').reverse().join('');
if (rev == str) 
  return true; 
else 
  return false;
Stephen James
@sjames1958gm
Jul 29 2017 23:44
@AnonymousLords Then you should do return rev === str;
John
@AnonymousLords
Jul 29 2017 23:44
Okay
kumquatfelafel
@kumquatfelafel
Jul 29 2017 23:45
You could also say here return rev === str :point_up: , or if return is not boolean,
return rev === str ? returnValueWhenTrue : returnValueWhenFalse;
John
@AnonymousLords
Jul 29 2017 23:45
whats ? mean
kumquatfelafel
@kumquatfelafel
Jul 29 2017 23:45
It's something referred to as conditional, or ternary, operator
John
@AnonymousLords
Jul 29 2017 23:46
Return the value of str if its not a boolean basically
like else
Jim Tryon
@jimtryon
Jul 29 2017 23:47
Object.keys.map(dict) not a function
kumquatfelafel
@kumquatfelafel
Jul 29 2017 23:47

@AnonymousLords In this particular example, equivalent using conditional operator would be

return rev === str? true: false;

John
@AnonymousLords
Jul 29 2017 23:48
Would both work
kumquatfelafel
@kumquatfelafel
Jul 29 2017 23:48

@jimtryon Object.keys is only a reference to function. Does not retrieve the array of keys which you need to call map on. You need to call function for that.

Assume blah is a function.
function call: blah();
function reference: blah;

John
@AnonymousLords
Jul 29 2017 23:50
unexpected token? @kumquatfelafel
retun rev == str? true: false;
retun rev == str? true: false;
^
CallMeOrange
@EgnaroDev
Jul 29 2017 23:51
retun
John
@AnonymousLords
Jul 29 2017 23:51
;-;
CallMeOrange
@EgnaroDev
Jul 29 2017 23:51
return (rev == str) ? true: false;
inside () is a condition
John
@AnonymousLords
Jul 29 2017 23:52
function palindrome(str) {
str = str.toLowerCase().replace(/[^0-9a-z]/g, "");
var rev = str.split('').reverse().join('');
return (rev == str) ? true: false;
}
toLowerCase is not a function
I don't get this error when i do aif statement on return :P
CallMeOrange
@EgnaroDev
Jul 29 2017 23:53
Hm.. looks like it will works, let me run a test
John
@AnonymousLords
Jul 29 2017 23:53

Babel Compiler v6.4.4
Copyright (c) 2014-2015 Sebastian McKenzie

TypeError: str.toLowerCase is not a function
at palindrome:3:13
at eval:8:1
at eval
at r.<anonymous>

Jim Tryon
@jimtryon
Jul 29 2017 23:54
@kumquatfelafel So you are saying I need to do Object.keys(dict).map()?
CallMeOrange