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
John Nunns
@johnnunns
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
JD Tadlock
@jdtdesigns
correct
you can use this site to test your regex https://regex101.com/
John Nunns
@johnnunns
ok I get to this point and now I'm thinking I need a regex method. What would I search?
or do I need to do any matching at all?
yeah I will actually I see it's going to pass a string that has the same word multiple times
@jdtdesigns
JD Tadlock
@jdtdesigns
you need to match words, but probably remove special characters like commas, question marks and such
John Nunns
@johnnunns
I think once again they're going more basic than that
all lower case string sentences
JD Tadlock
@jdtdesigns
they might not have any special characters
i'm just thinking of what fcc usually does lol
they do a ton of test cases
John Nunns
@johnnunns
not here lol we're still "basic"
John Nunns
@johnnunns
@jdtdesigns yikes man trying to find the regex match words in mdn and not finding anything only character matches
JD Tadlock
@jdtdesigns
@johnnunns It's very easy to match words
/(myWord)/g would be the regex
John Nunns
@johnnunns
haha why isn't that the first thing I see after searching regex match words?
JD Tadlock
@jdtdesigns
this is a good one for .match()
i just typed 'match a word regex' to test and it's the first response lol
@johnnunns
John Nunns
@johnnunns
no way!
haha
google?
JD Tadlock
@jdtdesigns
yep
John Nunns
@johnnunns
/\b($word)\b/i
does that one work?
JD Tadlock
@jdtdesigns
/(word)/g
easy
John Nunns
@johnnunns
function countWords(str) {
    str.split(' ')
    .reduce(function(result, word){
        var regex = new Regexp(/word/g)

    },{})
    return result
how are we looking? @jdtdesigns
JD Tadlock
@jdtdesigns
@johnnunns That won't work because the regex will only match the word 'word' ;)
you need to create the expression using a string and concat the word into it
new RegExp('expression', 'options')
options would just be 'g' for this one
John Nunns
@johnnunns
g is global?
JD Tadlock
@jdtdesigns
and you don't need the two '/' in the expression string
yes
John Nunns
@johnnunns
I'm really not sure JD I only put /word/g in there because you said haha
JD Tadlock
@jdtdesigns
/(word)/g is the expression to match 'word'
Darth Skywalker
@adityaparab

@johnnunns

g is global?

g is global as in it will match all occurances. Otherwise, Reg Ex only matches first occurance.