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
haha I thought we matched them already?
JD Tadlock
@jdtdesigns
the regex is just regex lol
it needs to be used somehow
John Nunns
@johnnunns
ok fair enough. so how about result[word] = str.match(regex)?
.length
h1tag
@h1tag
How do you create html elements using jquery? I found multiple ways on google, not sure which one is right.
John Nunns
@johnnunns
it's definitely wrong after submitting haha, but a good try right
?
man I hope my learning curve is at least on par with everyone else, this stuff is hard... @jdtdesigns
JD Tadlock
@jdtdesigns
@johnnunns str.match(regex).length should work ;)
John Nunns
@johnnunns
ok let me show you the whole thing then maybe error is somewhere else
JD Tadlock
@jdtdesigns
you need to return result below the .match
John Nunns
@johnnunns
function countWords(str) {
    str.split(' ')
    .reduce(function(result, word){
        var regex = new Regexp( '(' + word + ')', 'g');
        result[word] = str.match(regex).length
      return result;
    },{})

}

countWords("hey whta updsls a dgfg s")
JD Tadlock
@jdtdesigns
return str.split(' ').....
John Nunns
@johnnunns
ohh
right
Ritvars
@RitvarsZ
@fortMaximus I think that there is no wrong way. Use .append or .html or whatever fits your needs
John Nunns
@johnnunns
Regexp is not defined
JD Tadlock
@jdtdesigns
@fortMaximus var link = $('</ li>');
it's RegExp not Regexp
@johnnunns
John Nunns
@johnnunns
passing 1 of 3!
pretty good! :) haha
h1tag
@h1tag
@jdtdesigns then how do I add it to html file/code?
John Nunns
@johnnunns
weird though man it's working just fine. But I'm failing at :
should_return_an_object_where_each_property_gives_a_word_in_the_string_with_its_number_of_appearances
should_return_an_object_empty_object_ifpassed
JD Tadlock
@jdtdesigns
@fortMaximus sorry, that's 2.1
in version 3 just use $('h1');
@fortMaximus what are you trying to do?
@johnnunns Show me some test cases they are passing to your function
John Nunns
@johnnunns
found the error not sure how to fix
'ask a bunch get a bunch' returns - { ask: 1, a: 3, bunch: 2, get: 1 }
so it's returning 'a' 3 times
JD Tadlock
@jdtdesigns
correct
cause a is a word
and it's in there 3 times :D
o wait
2 times
h1tag
@h1tag
@jdtdesigns I'm on the Wiki Viewer project, and I want add the links I get from the response (links to wiki pages) from the API to the html file as paragraphs or list elements
John Nunns
@johnnunns
yeah weird right? @jdtdesigns
JD Tadlock
@jdtdesigns
@johnnunns Here's a way to overcome that bug
var regex = new RegExp('(' + word + ')', 'g'),
  amount = str.match(regex).length,
  output = amount < 2 ? amount : 
    word.length < 2 ? amount - 1 : amount;
John Nunns
@johnnunns
how'd you go about figuring that out?
JD Tadlock
@jdtdesigns
coded it out just now :D
John Nunns
@johnnunns
I want to know the thought process behind it
JD Tadlock
@jdtdesigns
did it work?
that's the first question lol
John Nunns
@johnnunns
amount is not defined
JD Tadlock
@jdtdesigns
result[word] = output;
John Nunns
@johnnunns
function countWords(str) {
    if(str.length===0){
        return {};
    }
    return str.split(' ')
    .reduce(function(result, word){
        var regex = new RegExp( '(' + word + ')', 'g');
        output = amount < 2 ? amount : 
        word.length < 2 ? amount - 1 : amount;
        result[word] = output

      return result;
    },{})

}

countWords("ask a bunch get a bunch")
still says amount is not defined