-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow words containing the end word character to be added to the trie. #8
- Loading branch information
1 parent
df2fc30
commit 9fd037d
Showing
6 changed files
with
150 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,75 @@ | ||
{ | ||
"name": "trie-prefix-tree", | ||
"version": "0.0.0-development", | ||
"description": "Create and modify trie prefix structures, extract word lists including anagrams and sub-anagrams", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "babel --out-dir dist src", | ||
"prebuild": "rimraf dist", | ||
"lint": "eslint src", | ||
"report-coverage": "codecov", | ||
"test": "jest", | ||
"test-coverage": "jest --coverage", | ||
"test-watch": "jest --watch", | ||
"commit": "git-cz", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/lyndseybrowning/trie-prefix-tree" | ||
}, | ||
"keywords": [ | ||
"javascript", | ||
"trie", | ||
"words" | ||
], | ||
"files": [ | ||
"dist", | ||
"README.md" | ||
], | ||
"author": "Lyndsey Browning <lbrowning86@gmail.com> (http://lyndseyb.co.uk/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/lyndseybrowning/trie-prefix/issues" | ||
}, | ||
"homepage": "https://github.com/lyndseybrowning/trie-prefix#readme", | ||
"devDependencies": { | ||
"babel-cli": "^6.22.2", | ||
"babel-core": "^6.22.1", | ||
"babel-jest": "18.0.0", | ||
"babel-plugin-add-module-exports": "0.2.1", | ||
"babel-plugin-array-includes": "2.0.3", | ||
"babel-plugin-transform-object-rest-spread": "^6.22.0", | ||
"babel-preset-env": "1.1.8", | ||
"babel-preset-es2015": "^6.22.0", | ||
"codecov": "1.0.1", | ||
"commitizen": "2.9.6", | ||
"cz-conventional-changelog": "1.2.0", | ||
"eslint": "^3.15.0", | ||
"ghooks": "2.0.0", | ||
"jest": "^18.1.0", | ||
"rimraf": "^2.5.4", | ||
"semantic-release": "^6.3.2" | ||
}, | ||
"jest": { | ||
"coverageDirectory": "./coverage", | ||
"collectCoverage": true, | ||
"transform": { | ||
".*": "<rootDir>/node_modules/babel-jest" | ||
"name": "trie-prefix-tree", | ||
"version": "0.0.0-development", | ||
"description": "Create and modify trie prefix structures, extract word lists including anagrams and sub-anagrams", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "babel --out-dir dist src", | ||
"prebuild": "rimraf dist", | ||
"lint": "eslint src", | ||
"report-coverage": "codecov", | ||
"test": "jest", | ||
"test-coverage": "jest --coverage", | ||
"test-watch": "jest --watch", | ||
"commit": "git-cz", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
}, | ||
"moduleFileExtensions": [ | ||
"js", | ||
"json", | ||
"es6" | ||
] | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "node_modules/cz-conventional-changelog" | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/lyndseybrowning/trie-prefix-tree" | ||
}, | ||
"ghooks": { | ||
"pre-commit": "npm run lint && npm run test" | ||
"keywords": [ | ||
"javascript", | ||
"trie", | ||
"words" | ||
], | ||
"files": [ | ||
"dist", | ||
"README.md" | ||
], | ||
"author": "Lyndsey Browning <lbrowning86@gmail.com> (http://lyndseyb.co.uk/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/lyndseybrowning/trie-prefix/issues" | ||
}, | ||
"homepage": "https://github.com/lyndseybrowning/trie-prefix#readme", | ||
"devDependencies": { | ||
"babel-cli": "^6.22.2", | ||
"babel-core": "^6.22.1", | ||
"babel-jest": "18.0.0", | ||
"babel-plugin-add-module-exports": "0.2.1", | ||
"babel-plugin-array-includes": "2.0.3", | ||
"babel-plugin-transform-object-rest-spread": "^6.22.0", | ||
"babel-preset-env": "1.1.8", | ||
"babel-preset-es2015": "^6.22.0", | ||
"codecov": "1.0.1", | ||
"commitizen": "2.9.6", | ||
"cz-conventional-changelog": "1.2.0", | ||
"eslint": "^3.15.0", | ||
"ghooks": "2.0.0", | ||
"jest": "^18.1.0", | ||
"rimraf": "^2.5.4", | ||
"semantic-release": "^6.3.2" | ||
}, | ||
"jest": { | ||
"verbose": false, | ||
"coverageDirectory": "./coverage", | ||
"collectCoverage": false, | ||
"transform": { | ||
".*": "<rootDir>/node_modules/babel-jest" | ||
}, | ||
"moduleFileExtensions": [ | ||
"js", | ||
"json", | ||
"es6" | ||
] | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "node_modules/cz-conventional-changelog" | ||
}, | ||
"ghooks": { | ||
"pre-commit": "npm run lint && npm run test" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
import config from './config'; | ||
import utils from './utils'; | ||
|
||
export default function append(trie, letter, index, array) { | ||
trie[letter] = trie[letter] || {}; | ||
trie = trie[letter]; | ||
const isEndWordLetter = letter === config.END_WORD; | ||
const isLastLetter = index === array.length - 1; | ||
|
||
if(index === array.length - 1) { | ||
if(isEndWordLetter && !isLastLetter) { | ||
trie[config.END_WORD] = 1; | ||
trie[config.END_WORD_REPLACER] = {}; | ||
trie = trie[config.END_WORD_REPLACER]; | ||
} else { | ||
trie[letter] = trie[letter] || {}; | ||
trie = trie[letter]; | ||
} | ||
|
||
if(isLastLetter) { | ||
trie[config.END_WORD] = 1; | ||
} | ||
|
||
return trie; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
END_WORD: '$', | ||
END_WORD_REPLACER: '9a219a89-91cd-42e2-abd5-eb113af08ca8', | ||
PERMS_MIN_LEN: 2, | ||
}; |
Oops, something went wrong.