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
@johnnunns It depends on the way you're coding it
John Nunns
@johnnunns
what's the '[^' @jdtdesigns
JD Tadlock
@jdtdesigns
The ^ matches everything except that character
Ve Vanderpool
@VanAmoVe
@jdtdesigns thank you, I think I see what your are saying brb
CamperBot
@camperbot
vanamove sends brownie points to @jdtdesigns :sparkles: :thumbsup: :sparkles:
:cookie: 877 | @jdtdesigns |http://www.freecodecamp.com/jdtdesigns
JD Tadlock
@jdtdesigns
@johnnunns
John Nunns
@johnnunns
someone in the js help spot just solved it before you logged in. While your code passes 2/3 tests, this code passes all. @jdtdesigns
function countAllCharacters(str) {
  // your code here
    var array = str.split("")
  var object = {};

  if(str.length === 0) return object;
  else{
  for(var i = 0; i < array.length; i++){
    if(object[array[i]]) object[array[i]]++;
    else object[array[i]] = 1;
  }
  return object;
  }

}

var output = countAllCharacters('banana');
console.log(output);
can you spot a difference?
JD Tadlock
@jdtdesigns
@johnnunns It's counting spaces lol
John Nunns
@johnnunns
your code is? @jdtdesigns
JD Tadlock
@jdtdesigns
nope
i removed all non word charactes
characters*
John Nunns
@johnnunns
yeap works
JD Tadlock
@jdtdesigns
John Nunns
@johnnunns
doesn't run html
:) haha didn't see it's on the other side
oops
only completes 1 of 3 tests @jdtdesigns
well the third one should be an easy fix it returns and empty object if it's an empty string
Chadd Williams
@chaddd980
hey, so i am trying to learn react, and i am making a tic tac toe game. anyway, this is the piece of code that i have for trying to check if there is a winner. when i test it, it hits my debugger when there is 3 in a row, so i know the function is running properly. but the alert will never appear. and when i type in this.checkForWinner in the console, it gives me undefined. I'm pretty lost and don't know what the issue is, or what to do
  checkForWinner() {
    var combos = [[0,1,2], [0,3,6], [0,4,8], [1,4,7], [2,5,8], [2,4,6], [3,4,5], [6,7,8]]
    combos.find(function(combo) {
      if(this.state.board[combo[0]] !== "" && this.state.board[combo[0]] === this.state.board[combo[1]] && this.state.board[combo[1]] === this.state.board[combo[2]]) {
debugger
        return this.state.board[combo[0]]
      } else {
        return false
      }
    }.bind(this))
  }

  componentDidUpdate() {
    if (this.checkForWinner()) {
      debugger
      alert("winner!!")
    }
  }
JD Tadlock
@jdtdesigns
@johnnunns put this inside the function on the challenge :
return string.replace(/(.)(?=.*\1)/g, '')
    .split('')
    .reduce(function(result, letter) {
      var regex = new RegExp('[^' + letter + ']', 'g');
      result[letter] = string.replace(regex, '').length;

      return result;
  }, {})
i looked over the other person's code and they're not removing capital copies or non word characters
i over-complicated it basically :P
John Nunns
@johnnunns
that's the one! :)
do you mind explaining it?
string.replace
you're replacing everying inside / /
why the parentheses?
@jdtdesigns
JD Tadlock
@jdtdesigns
all you need to know is this expression '/(.)(?=.*\1)/g' replaces any duplicate copies of characters in the string
so i'm creating a string that has no duplicates, then iterating through each character and getting the amount of duplicates from the original string using string.replace(regex, '').length
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
JD Tadlock
@jdtdesigns
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