Coder Social home page Coder Social logo

lanpengyou125 / english-dictionary Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nsokolov114/english-dictionary

0.0 0.0 0.0 149 KB

10000 top English words in a txt file - for building your word games. Also includes 1000, 5000, 8000 and 13000 words dictionaries and code samples for JS

english-dictionary's Introduction

English Dictionary for building your Hangman game

There are few txt files containing a number of top English words:
~ 1000 most used English words (best for testing)
~ 5000 most used English words
~ 8000 most used English words
~ 10000 most used English words (best for playing)
~ 13000 most used English words

Disclaimer

Those are the most used English words. I can't get a credit to the person who did this work of collecting a number of books and articles and sorting them - I downloaded those dictionaries in ~2010 and can't find the source.
You may find some of these words offensive.
You may find some remaining duplicates ('color' and 'colour')
You may find some of these words useless ('aye', 'an') or missing spaces or hyphens ('guineapig' instead of 'guinea pig'). I did my best to clean the dictionaries, but if you're going to use them commercially, make sure to check the words first.

How to use the Dictionary (JavaScript)

Generate the array from the dictionary string:

const tmp = 'copy-paste all the words from the txt file';
const dictionary = tmp.split(', ');  // ['ABLE', 'ABOUT', 'ABOVE', ...]

Get a random word from your dictionary:

function getRandomWord() {
  return dictionary[Math.floor(Math.random() * dictionary.length)];
}
let word = getRandomWord();
console.log(word);  // HELLO

You may set the minimal length of the random word (it's hard to guess a really short word):

const minLength = 6;
let longerWord = '';
let counter = 0;

// run the cycle until we find a word that meets the requirements:
while (longerWord.length < minLength) { 
  longerWord = getRandomWord();
  counter++;
  if (counter > 1000) {  
    console.log('Failed to find a long enough word!');
    break;               // prevents getting into the infinite loop
  }                      // if conditions you've set are too strict 
}
console.log(longerWord); // COOKIE

You can use this code sample to also set a maximum length, or generate a word with fixed length:

const maxLength = 8;
while (longerWord.length < minLength || longerWord.length > maxLength) {...};

const fixedLength = 6;
while (longerWord.length !== fixedLength) {...};

english-dictionary's People

Contributors

nsokolov114 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.