Coding Challenge #40.1: Word Counter in JavaScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ธ.ค. 2024

ความคิดเห็น •

  • @mycomputerfund
    @mycomputerfund 6 ปีที่แล้ว +10

    It's disrespectful that this video has 20k views and only 280 likes... This content is excellent. I love your explanation and 'hand-holding' of concepts. You're a natural teacher.

  • @SonofThor420
    @SonofThor420 8 ปีที่แล้ว +2

    Just found your videos. Man, you're such a great teacher! Your enthusiasm and expertise make it so fun AND easy to learn these complex topics. Well done, sir.

  • @occieholloway6523
    @occieholloway6523 4 ปีที่แล้ว +1

    Thank you for being God bless you and yours this season 🎊🎉🙏

  • @Aglaophamus1
    @Aglaophamus1 7 ปีที่แล้ว +3

    Awesome video! Love your enthusiasm and clear explanations. Thanks so much for putting this up.

  • @followthetrawler
    @followthetrawler 7 ปีที่แล้ว

    I'm not a javascript coder, but this has given me some good ideas elsewhere - thank you!

  • @Thiago-jm7gr
    @Thiago-jm7gr 5 ปีที่แล้ว +1

    Another ways you can count words frequency:
    var arr = 'This is a sample'.split(/\W+/)
    const freq = {}
    const getWordsFreq = wordsArr => wordsArr.reduce((freq, word) => {
    freq[word] = ++freq[word] || 1
    return freq
    }, {})
    getWordsFreq(arr)
    *Or alternatively in ONE line:*
    const getWordsFreq = words => words.forEach(word => freq[word] = ++freq[word] || 1)

  • @josephchavez6618
    @josephchavez6618 3 ปีที่แล้ว +1

    what about bigrams?

  • @occieholloway6523
    @occieholloway6523 4 ปีที่แล้ว +1

    Thank you

  • @topcha222
    @topcha222 8 ปีที่แล้ว +5

    you are best coder in my opinion!

  • @Jack-4242
    @Jack-4242 4 ปีที่แล้ว

    7:20 You can also check "word in counts". Does anyone know if this makes some difference to his approach?

  • @nocaster51
    @nocaster51 6 ปีที่แล้ว +3

    I should probably go cold turkey on Coding Train. 3h+ lessons a day that's plenty :)

  • @mdeekshitulu
    @mdeekshitulu 7 ปีที่แล้ว +1

    Great one. Thanks :)

  • @elysel9424
    @elysel9424 5 ปีที่แล้ว +2

    you should have wayyyy more subscribers

  • @oneplus1861
    @oneplus1861 4 ปีที่แล้ว

    This channel is LIT💕

  • @diwasrai1131
    @diwasrai1131 7 ปีที่แล้ว

    I have a noob question. On the if statement, how does incrementing an 'object "key" equals the increase in count in "value" ? I understand the declaration of value to 1, if the word (aka counts[word] ) is undefined. But if it exists why does counts[word]++ define the value of the key?

  • @twofacil
    @twofacil 3 ปีที่แล้ว

    I cannot find the fuction loadString in intelij. Any ideas how to find it?

  • @royopov
    @royopov 8 ปีที่แล้ว

    What's the syntax theme do you use?

    • @mikeynjs94
      @mikeynjs94 8 ปีที่แล้ว

      He's coding in JavaScript with the p5.js library.

  • @FellTheSky
    @FellTheSky 4 ปีที่แล้ว

    the count.sort(compare) part is not working. It says a its undefined. Is that a p5 function or a javascript function?

  • @aaronbuckles8755
    @aaronbuckles8755 8 ปีที่แล้ว

    I'm confused on how the compare function works. What is a and b and how are we passing the into the function?

    • @adriang4578
      @adriang4578 7 ปีที่แล้ว

      Same with me.
      Could you figure it out in the meantime?

  • @WildAnimalChannel
    @WildAnimalChannel 7 ปีที่แล้ว

    god bless you sir!

  • @Ny_babs
    @Ny_babs 5 ปีที่แล้ว

    This no longer works. I am not sure if it is something to do with linking the txt to the html doc. Help?!

  • @mad-9550
    @mad-9550 8 ปีที่แล้ว

    thanks coach

  • @setupdraw7642
    @setupdraw7642 8 ปีที่แล้ว

    I've noticed that if you just use if (counts[word]) { ..... It is not working properly , infact I got NAN instead of the numbers. So I think (counts[word] === undefined) is necesssary. Can anyone explain the reason for that?
    Another thing I do not understand completely is how the function compare(a,b){.... works.
    What gets passed in and how the ordering is made is quite obscure to me.
    BTW Great Coding Challenge Dan!

  • @NonTwinBrothers
    @NonTwinBrothers 7 ปีที่แล้ว

    I've always loved and hated learning string patterns. They're extremely useful to use and make you look super smart but they're terribly hard to learn.

  • @Doug07Ferron
    @Doug07Ferron 5 ปีที่แล้ว

    Genius! :)

  • @mirtuchy8762
    @mirtuchy8762 7 ปีที่แล้ว

    Genius

  • @KOKOMAKING
    @KOKOMAKING 7 ปีที่แล้ว

    hi. i just want to make spelling bee aplication in javascript, but i don't know how to make the code. can you tell me how to make it ? thnks

    • @TheCodingTrain
      @TheCodingTrain  7 ปีที่แล้ว

      Oh, I like this idea! Please suggest here! github.com/CodingTrain/Rainbow-Topics/issues

  • @akashdeeps3704
    @akashdeeps3704 7 ปีที่แล้ว

    How did he get that console????

    • @adriang4578
      @adriang4578 7 ปีที่แล้ว

      on chrome go to developer-tools or on firefox cmd-alt-i

  • @jerneje
    @jerneje 8 ปีที่แล้ว

    why not create an array of objects with both values in the first place ?

    • @TheCodingTrain
      @TheCodingTrain  8 ปีที่แล้ว

      Having the array only does not allow lookup by the word itself.

    • @jerneje
      @jerneje 8 ปีที่แล้ว

      you could use something like "find" (developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find) for the lookup, just not sure how efficient it would be.
      But in your case it seems tedious, to manage multiple data sources

    • @ztsb45
      @ztsb45 8 ปีที่แล้ว

      Would this algorithm be faster than, say, taking the first word, creating a copy of the word and keeping a count in a tuple, and then counting every occurrence of that word in the string before replacing each one with a blank space or other symbol that the loop can recognize and skip over? That is to say, each new word it encounters, it takes a new count of that word and replaces each occurrence with a symbol to be skipped over in the next cycle through the string.
      You could probably use that as a way to parallelize it, as well, with a new thread for each new word or something. IF you did it like that, I imagine you'd make a head thread that has a list of the already seen words, and it would kick off a new thread for each new word it found. In that case, it wouldn't even have to use the replace idea, it could just not start new threads for already seen words.

  • @jacekudi
    @jacekudi 8 ปีที่แล้ว

    hello everybody, I got this rather tedious way for excluding some words in the counter:
    for (var j = 0; j < keys.length; j++) {
    var k = keys[j];
    if (k != 'the' &&
    k != 'and' &&
    k != 'of' &&
    k != 'to' &&
    k != 'a' &&
    k != 'in') {
    createDiv(" " + k + " " + counts[k]);
    }
    }
    can we make it with array difference in p5? Some shorter solution?

    • @mossberg9352
      @mossberg9352 8 ปีที่แล้ว

      Jacek Patryk Urbanowicz would be much easier to put your words that you don't want in array like so:
      skipWords = ['the', 'so', 'and'];
      for (var i=0; i < skipWords.length; i++) {
      if (k==skipWords[i]) {
      createDiv(k)
      break
      }
      put that in your for loop. hope it helps, I'm on mobile!

  • @AnirudhGiri
    @AnirudhGiri 7 ปีที่แล้ว

    He should've counted the word frequencies of the Bee movie script instead... :P

  • @emilie1977
    @emilie1977 8 ปีที่แล้ว

    Do you know a method for hyphenation?

    • @emilie1977
      @emilie1977 8 ปีที่แล้ว

      Excuse me: separate into distinct syllables

  • @normankang5004
    @normankang5004 8 ปีที่แล้ว +3

    Wait, why do we always use p5.js? Why not just javascript? Is using just javascript too advanced?

  • @darshanrajadhyaksha8211
    @darshanrajadhyaksha8211 8 ปีที่แล้ว

    Word counter with graph :- codingflag.in/mysketch.php?sketch=95

  • @espertalhao041
    @espertalhao041 8 ปีที่แล้ว +2

    You have a HUGE!!!! problem. What if, by accident, you have a word that is part of the prototype? That should break some stuff. What you can do is to append a NULL-char at the beginning. That is, instead of `counts[key]`, you use `counts['\0' + key]` everywhere where you have to access `key`.

  • @peristiloperis7789
    @peristiloperis7789 6 ปีที่แล้ว

    I thought this would be made in pure Javascript. Not useful for me.