Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 17:13
    @mstellaluna banned @cmal
  • Jan 08 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
  • Jul 29 2018 01:00
    @bjorno43 banned @jkyereh
  • Jul 10 2018 22:09
    @bjorno43 banned @manafn
  • Jul 06 2018 15:20
    @texas2010 banned @imlegend19
  • Jul 03 2018 12:28
    @bjorno43 banned @vbvmatta
  • Jun 29 2018 13:54
    @bjorno43 banned @OGTechnoBoy
JD Tadlock
@jdtdesigns
a simple regex to match everything except a single character is [^a] where 'a' is the character to leave out
the '/g' at the end just means to match as many as it can find in the entire string
without the 'g' it would just find the first then stop
make sense at all @johnnunns ?
John Nunns
@johnnunns
that top expression is just a known one to do that? and I can find that where when I need to look it up?
@jdtdesigns
JD Tadlock
@jdtdesigns
any regex can be found pretty quickly with google :P
John Nunns
@johnnunns
what would I type into google to find that?
JD Tadlock
@jdtdesigns
search 'replace duplicates regex'
John Nunns
@johnnunns
gotcha
JD Tadlock
@jdtdesigns
like i said before, i'm not a master regex'er
i google a lot myself when the need rises
John Nunns
@johnnunns
right on
ok cool so duplicate copies of characters
Abdijabar Yussuf Mohamed
@aymohamed
Hello guys, Any suggestion on how I can improve my tribute page ? https://codepen.io/aymohamed/pen/egWgmQ
John Nunns
@johnnunns
don't we need those duplicates thought o count those?
to*
instead of replacing them?
I guess what I'm not seeing is the need for the replace code
Abdijabar Yussuf Mohamed
@aymohamed
Hello guys, Any suggestion on how I can improve my tribute page ? https://codepen.io/aymohamed/pen/egWgmQ
JD Tadlock
@jdtdesigns
@johnnunns I basically through that in to thwart any potential errors and didn't even try it without it. It actually works without the replacement :P
John Nunns
@johnnunns
yeah just tried it too :)
ok we just shortened our code! you're right though may not be error proof now :)
Chadd Williams
@chaddd980
@aymohamed the picture of mandela isn't centered. thats one thing i'd fix
Abdijabar Yussuf Mohamed
@aymohamed
Ok. @chaddd980 , let me try
John Nunns
@johnnunns
function countAllCharacters(string){

return string.split('')
    .reduce(function(result, letter) {
      var regex = new RegExp('[^' + letter + ']', 'g');
      result[letter] = string.replace(regex, '').length;

      return result;
  }, {})
}

countAllCharacters('banana')
Abdijabar Yussuf Mohamed
@aymohamed
@chaddd980 , how about this now? https://codepen.io/aymohamed/pen/egWgmQ
John Nunns
@johnnunns
@jdtdesigns alright, since you pretty much walked me through that, I should be able to complete this one still maybe with a bit of help
thanks for everything so far though @jdtdesigns
CamperBot
@camperbot
johnnunns sends brownie points to @jdtdesigns :sparkles: :thumbsup: :sparkles:
:cookie: 878 | @jdtdesigns |http://www.freecodecamp.com/jdtdesigns
John Nunns
@johnnunns
ok the next one - very similar
Instructions from your teacher:
Write a function called "countWords".

Given a string, "countWords" returns an object where each key is a word in the given string, with its value being how many times that word appeared in th given  string. 

Notes:
* If given an empty string, it should return an empty object.

var output = countWords('ask a bunch get a bunch'); 
console.log(output); // --> {ask: 1, a: 2, bunch: 2, get: 1}

Starter Code : 
function countWords(str) {
  // your code here
}
I'm going to not look at the code you just gave me and lets see if I can figure this out
JD Tadlock
@jdtdesigns
@johnnunns lol, good luck ;)
Abdijabar Yussuf Mohamed
@aymohamed
Any hint on how I can link my html code with the CSS
?
John Nunns
@johnnunns
function countWords(str) {
    str.split(' ')
    .reduce()
}
@jdtdesigns and that's how far I got. hows that for retention :) hahaha @jdtdesigns
reduce(function(sum, words)?
JD Tadlock
@jdtdesigns
the first arg is the result or thing you'll be creating after the reduce is finished
so in your case an object
John Nunns
@johnnunns
and not to go to far ahead, but the {}) at the end of the reduce is to pass it into those brackets correct?
JD Tadlock
@jdtdesigns
words would be word because you're splitting the str into words and the second arg will refer to each 'word' in the split array
the {} at the end refers to the result arg
.reduce(result, word)
where result is {}
so the result starts as an empty object and you add to it in the function
John Nunns
@johnnunns
gotcha, that's why with a sum reduce you can make the sum start at 0