Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:33
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • May 10 09:13
    @bjorno43 banned @zhaokunhaoa
  • Apr 25 17:12
    @mstellaluna banned @cmal
  • Apr 01 18:11
    thecodingaviator labeled #31179
  • Apr 01 18:11
    thecodingaviator labeled #31179
  • Apr 01 18:09
    thecodingaviator commented #31179
  • Apr 01 18:09
    thecodingaviator labeled #31182
  • Apr 01 18:09
    thecodingaviator labeled #31182
  • Apr 01 18:07
    thecodingaviator commented #31182
  • Apr 01 18:07
    thecodingaviator labeled #31190
  • Apr 01 18:07
    thecodingaviator labeled #31190
  • Apr 01 18:07
    thecodingaviator commented #31190
  • Apr 01 18:05
    thecodingaviator commented #31157
  • Apr 01 18:04

    thecodingaviator on master

    remove A (#31157) (compare)

  • Apr 01 18:04
    thecodingaviator closed #31157
  • Apr 01 18:04
    thecodingaviator closed #33788
  • Apr 01 18:04
    thecodingaviator commented #33788
  • Apr 01 18:02
    thecodingaviator closed #31059
  • Apr 01 18:02
    thecodingaviator commented #31059
kumquatfelafel
@kumquatfelafel
@Hijerboa One thing I will say is that strings are immutable. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase
As a result, your toLowerCase actually does not change your original string, but returns a new string that you do nothing with.
Moisés Man
@moigithub
\w includes _
soo that regex will KEEP _ @Hijerboa and spaces
Nick Cleary
@Hijerboa
@kumquatfelafel so I should make an new variable with the toLowerCase, like I did with the replace?
@moigithub ah ok thank you
CamperBot
@camperbot
hijerboa sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3439 | @moigithub |http://www.freecodecamp.com/moigithub
kumquatfelafel
@kumquatfelafel
@Hijerboa You don't necessarily need to create a new variable for everything you do. You can also chain your functions or reassign into old variables.
Saif Ur Rahman
@saifsmailbox98
@Hijerboa you are comparing with str, it contains non-alphanumeric characters.
reverse() changes the original array.
toLowerCase() only returns the lowercased vaue.
kumquatfelafel
@kumquatfelafel
For example, since toLowerCase returns a string, you can actually call it then call replace on that returned string immediately afterwards.
str = str.toLowerCase().replace(blahblahblah);
Nick Cleary
@Hijerboa
function palindrome(str) {
  var newString = str.toLowerCase().replace(/[^a-z]/gi, '').split("").reverse().join();
  if(newString === str){
    return true;
  } else {
    return false;
  }

}
this is my new code and it isn't working. I chained the expressions like you said @kumquatfelafel
Saif Ur Rahman
@saifsmailbox98
@Hijerboa [^a-z0-9]
kumquatfelafel
@kumquatfelafel
^. You want to keep numbers as well.
Saif Ur Rahman
@saifsmailbox98
join need a paramater join("")
Nick Cleary
@Hijerboa
fixed those issues... still won't work with anything with a non-alpha numeric character
Saif Ur Rahman
@saifsmailbox98
@Hijerboa you first need to lowercase and replace all non-alphanumeric character from str and assign it back to str, so that later you can compare with it.
kumquatfelafel
@kumquatfelafel

^this as well.

You can also say return newString === str. That's logically equivalent to your if-else return statements.

Nick Cleary
@Hijerboa
@saifsmailbox98 @kumquatfelafel that worked for all but one of them
function palindrome(str) {
  str = str.toLowerCase().replace(/[^a-z]/gi, '');
  var newString = str.toLowerCase().replace(/[^a-z]/gi, '').split("").reverse().join("");

  if(newString === str){
    return true;
  } else {
    return false;
  }

}
Moisés Man
@moigithub
@Hijerboa u need to KEEP numbers too
Saif Ur Rahman
@saifsmailbox98
@Hijerboa :point_up: June 28, 2017 6:15 AM
kumquatfelafel
@kumquatfelafel
@Hijerboa [^a-z0-9]
Nick Cleary
@Hijerboa
facepalm I added that then removed it on accident later
Saif Ur Rahman
@saifsmailbox98
@Hijerboa str is already lowercased and you have already removed non-alphanumeric characters
Nick Cleary
@Hijerboa
thank you guys....
Moisés Man
@moigithub
@Hijerboa if u have already a "cleaned" str.. u can reuse it..
kumquatfelafel
@kumquatfelafel
@Hijerboa you also don't need to do the tolower/replace again :p
Nick Cleary
@Hijerboa
thank you so much @moigithub @saifsmailbox98 @kumquatfelafel
CamperBot
@camperbot
hijerboa sends brownie points to @moigithub and @saifsmailbox98 and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 376 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:warning: hijerboa already gave moigithub points
:cookie: 637 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
Moisés Man
@moigithub
no need to call replace and tolowercase again
also... this comparison (newString === str return a boolean value true or false..
soo u can directly return the result of that
return newString === str; @Hijerboa
and remove the if
kumquatfelafel
@kumquatfelafel
hahaha... this is what happens when there are too few people asking questions ^^^ :P
Nick Cleary
@Hijerboa
removed the second instance of .replace and .toLowerCase :P
I prob would have punched my computer if it wasn't for you guys. You all rock
kumquatfelafel
@kumquatfelafel
@Hijerboa So... any other questions? Do you want to know how to bake a cake? Simplify your life? Travel back in time? We have those answers and more, and we're all ready and willing to help! :o
Brittani
@Carowyn
Hey, I came back to the perfect conversation...I'm about to attempt the Palindrome one. I'm taking a food break because I sat staring at my computer in confusion lol.
Nick Cleary
@Hijerboa
Yeah one quick question: whats the meaning of life?
One guy told me it was 41 or something
Stephen James
@sjames1958gm
42
kumquatfelafel
@kumquatfelafel
meaningOfLife++;
pablovvb
@pablovvb
So, this is as far as I got, which is nothing. Any hint of why I'm not filtering anything would be fully appreciated!!
function destroyer(arr) {
  // Remove all the values
  var arr2 = arr.slice.call(arguments);
  var arr1 = arr2.shift();
  var newArr = [];
  function a() { 
  return a !== arr2[i];   //this compares each element of arr1 to arr2
  }  
  for (i = 0; i < arr2.length; i++) {  
    newArr = arr1.filter(a);
  }  // deletes the similarities in arr1, and applies the changes to newArr  
//  var newArr = arr.filter(function(a) {return Boolean(!a);
   //                                          });  
  return newArr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Nick Cleary
@Hijerboa
@kumquatfelafel amazing
kumquatfelafel
@kumquatfelafel

@pablovvb a !== arr2[i]?

What is a?

pablovvb
@pablovvb
maybe there's it!!
kumquatfelafel
@kumquatfelafel
pablovvb
@pablovvb
hmm, I'm still not there. I need somehow to compare all the elements in arr1 to the elements in arr2, and a is not doing it because I don't mention arr1 anywhere
kumquatfelafel
@kumquatfelafel
@pablovvb There may be a function that does something along the lines of what you want. See if you can find one https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype