Skip to content

Instantly share code, notes, and snippets.

@julienreszka
Last active May 6, 2022 08:36
Show Gist options
  • Select an option

  • Save julienreszka/8f2f747f6319d04e30f3dc3802971064 to your computer and use it in GitHub Desktop.

Select an option

Save julienreszka/8f2f747f6319d04e30f3dc3802971064 to your computer and use it in GitHub Desktop.

Revisions

  1. julienreszka revised this gist May 6, 2022. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions basic-page-word-frequency.js
    Original file line number Diff line number Diff line change
    @@ -2,10 +2,11 @@ function wordFreq(string) {
    var words = string.replace(/[.]/g, '').split(/\s/);
    var freqMap = {};
    words.forEach(function(w) {
    if (!freqMap[w]) {
    freqMap[w] = 0;
    var lowerWord = w.toLowerCase()
    if (!freqMap[lowerWord]) {
    freqMap[lowerWord] = 0;
    }
    freqMap[w] += 1;
    freqMap[lowerWord] += 1;
    });

    var mostCommonWordsInEnglish =[
  2. julienreszka revised this gist Apr 1, 2022. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion basic-page-word-frequency.js
    Original file line number Diff line number Diff line change
    @@ -110,9 +110,13 @@ function wordFreq(string) {
    "most",
    "us"
    ]
    var mostCommonWordsInFrench = [
    "le", "de", "un", "et", "être", "il", "avoir", "ne", "je", "son", "que", "se", "qui", "en", "ce", "dans", "du", "elle", "au", "de", "ce", "le", "pour", "pas", "que", "vous", "par", "sur", "faire", "plus", "dire", "me", "on", "mon", "lui", "nous", "comme", "mais", "pouvoir", "avec", "tout", "y", "aller", "voir", "en", "bien", "où", "sans", "tu", "ou", "leur", "homme", "si", "deux", "mari", "moi", "vouloir", "te", "femme", "venir", "quand", "grand", "celui", "si", "notre", "devoir", "là", "jour", "prendre", "même", "votre", "tout", "rien", "encore", "petit", "aussi", "quelque", "dont", "tout", "mer", "trouver", "donner", "temps", "ça", "peu", "même", "falloir", "sous", "parler", "alors", "main", "chose", "ton", "mettre", "vie", "savoir", "yeux", "passer", "autre", "après"
    ]


    return Object.keys(freqMap).map(k=>{return {word: k,freq:freqMap[k]}})
    .filter((w)=>w.freq > 1 && !mostCommonWordsInEnglish.includes(w.word))
    .filter((w)=>w.freq > 1 && !mostCommonWordsInEnglish.includes(w.word) && !mostCommonWordsInFrench.includes(w.word))
    .sort((a,b)=>b.freq-a.freq);

    }
  3. julienreszka revised this gist Apr 1, 2022. 1 changed file with 104 additions and 1 deletion.
    105 changes: 104 additions & 1 deletion basic-page-word-frequency.js
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,111 @@ function wordFreq(string) {
    freqMap[w] += 1;
    });

    var mostCommonWordsInEnglish =[
    "the",
    "be",
    "to",
    "of",
    "and",
    "a",
    "in",
    "that",
    "have",
    "I",
    "it",
    "for",
    "not",
    "on",
    "with",
    "he",
    "as",
    "you",
    "do",
    "at",
    "this",
    "but",
    "his",
    "by",
    "from",
    "they",
    "we",
    "say",
    "her",
    "she",
    "or",
    "an",
    "will",
    "my",
    "one",
    "all",
    "would",
    "there",
    "their",
    "what",
    "so",
    "up",
    "out",
    "if",
    "about",
    "who",
    "get",
    "which",
    "go",
    "me",
    "when",
    "make",
    "can",
    "like",
    "time",
    "no",
    "just",
    "him",
    "know",
    "take",
    "people",
    "into",
    "year",
    "your",
    "good",
    "some",
    "could",
    "them",
    "see",
    "other",
    "than",
    "then",
    "now",
    "look",
    "only",
    "come",
    "its",
    "over",
    "think",
    "also",
    "back",
    "after",
    "use",
    "two",
    "how",
    "our",
    "work",
    "first",
    "well",
    "way",
    "even",
    "new",
    "want",
    "because",
    "any",
    "these",
    "give",
    "day",
    "most",
    "us"
    ]

    return Object.keys(freqMap).map(k=>{return {word: k,freq:freqMap[k]}})
    .filter((w)=>w.freq > 1)
    .filter((w)=>w.freq > 1 && !mostCommonWordsInEnglish.includes(w.word))
    .sort((a,b)=>b.freq-a.freq);

    }
  4. julienreszka revised this gist Apr 1, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion basic-page-word-frequency.js
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,8 @@ function wordFreq(string) {
    });

    return Object.keys(freqMap).map(k=>{return {word: k,freq:freqMap[k]}})
    .sort((a,b)=>b.freq-a.freq);
    .filter((w)=>w.freq > 1)
    .sort((a,b)=>b.freq-a.freq);

    }
    wordFreq(document.body.innerText)
  5. julienreszka created this gist Feb 16, 2022.
    14 changes: 14 additions & 0 deletions basic-page-word-frequency.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    function wordFreq(string) {
    var words = string.replace(/[.]/g, '').split(/\s/);
    var freqMap = {};
    words.forEach(function(w) {
    if (!freqMap[w]) {
    freqMap[w] = 0;
    }
    freqMap[w] += 1;
    });

    return Object.keys(freqMap).map(k=>{return {word: k,freq:freqMap[k]}})
    .sort((a,b)=>b.freq-a.freq);
    }
    wordFreq(document.body.innerText)