New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

boggle

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boggle - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

2

package.json
{
"name": "boggle",
"version": "0.0.1",
"version": "0.0.2",
"description": "Boggle grid solver",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -19,1 +19,55 @@ # Boggle solver

Case does not matter, it will be converted to lowercase.
## Main logic
The algorithm iterates over the 2D grid, trying to walk
depth first, while possible (including diagonally, but not
visiting same cell more than once). At each step, the accumulated
string is checked against the dictionary. Walking stops and
the algorithm backtracks to previous depth if the string
is no longer a valid word or valid word prefix.
// src/boggle.js
var uniqueWords = {};
paths(lowerCased, {
stepWhile: function (str, x, y, grid) {
if (dictionary.isWord(str)) {
// found whole word, maybe there is more!
uniqueWords[str] = true;
return true;
}
if (dictionary.isWordPrefix(str)) {
// not a word, but possible
return true;
}
}
});
var words = Object.keys(uniqueWords);
words = utils.validWords(words);
## Dependencies
To discover paths in the letter grid, I use [matrix-paths](https://bitbucket.org/bahmutov/matrix-paths). While walking through the matrix, I use boggle [prefix-dictionary](https://bitbucket.org/bahmutov/prefix-dictionary) that uses a [**trie**](http://en.wikipedia.org/wiki/Trie) data structure. Trie is a binary search tree that stores words in addition to children links, making word or prefix matching very quick.
## Testing and code complexity
To unit and function test the module, execute command
npm test
This might require installing [gt](https://npmjs.org/package/gt) testing tool globally
npm install -g gt
To see code complexity (it is very low), run command
npm run-script complexity
This might require installing [jsc](https://npmjs.org/package/jsc) tool globally
npm install -g jsc
## Todo
* Use jshint to see possible bugs

@@ -58,3 +58,3 @@ var check = require('check-types');

words = Object.keys(uniqueWords);
var words = Object.keys(uniqueWords);
words = utils.validWords(words);

@@ -61,0 +61,0 @@ return words;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc