@neopass/words-by-length-view
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

words-by-length-view

Organizes a word list by the length of the words.

For a source word list, see @neopass/wordlist

import { WordsByLengthView } from '@neopass/words-by-length-view'

// Use a set to avoid duplicate words.
let words = new Set([
  'some', 'words', 'in', 'a', 'list',
  'to', 'be', 'organized', 'by', 'length', 'by', 'the', 'view',
  'this', 'can', 'also', 'be', 'a', 'promise', 'that', 'returns', 'a', 'list',
  'or', 'a', 'wordlist', 'list', 'builder', 'function',
])

// Create the view, converting the set to an array.
const view = new WordsByLengthView([...words])

// Allow the set to be garbage collected.
words = null

// Get all words by length.
const allWords = view.get()
console.log(allWords)

// Get words of length from 3 to 6, inclusive.
const someWords = view.get(3, 6)
console.log(someWords)

All words output:

{
  words: {
    '1': [ 'a' ],
    '2': [ 'in', 'to', 'be', 'by', 'or' ],
    '3': [ 'the', 'can' ],
    '4': [ 'some', 'list', 'view', 'this', 'also', 'that' ],
    '5': [ 'words' ],
    '6': [ 'length' ],
    '7': [ 'promise', 'returns', 'builder' ],
    '8': [ 'wordlist', 'function' ],
    '9': [ 'organized' ]
  },
  stats: {
    totalWords: 22,
    shortestWord: 1,
    longestWord: 9,
    byLength: {
      '1': 1,
      '2': 5,
      '3': 2,
      '4': 6,
      '5': 1,
      '6': 1,
      '7': 3,
      '8': 2,
      '9': 1
    }
  }
}

Some words output:

{
  words: {
    '3': [ 'the', 'can' ],
    '4': [ 'some', 'list', 'view', 'this', 'also', 'that' ],
    '5': [ 'words' ],
    '6': [ 'length' ]
  },
  stats: {
    totalWords: 10,
    shortestWord: 3,
    longestWord: 6,
    byLength: {
      '3': 2, '4': 6, '5': 1, '6': 1
    }
  }
}

Package Sidebar

Install

npm i @neopass/words-by-length-view

Weekly Downloads

0

Version

0.1.2

License

MIT

Unpacked Size

16.7 kB

Total Files

19

Last publish

Collaborators

  • jabney