Closed iskrich closed 1 year ago
It would be helpful for my project. But If you think that it will be useful for all, I can make PR
I have naively implemented this by doing:
function word() {
return constants.wordListSmall[randInt(constants.wordListSmall.length)];
}
function randInt(lessThan) {
return Math.floor(Math.random() * lessThan);
}
function findWord(){
let _word = word();
while (String(_word).length <= constants.utils.wordLengthBase) {
_word = word();
}
return _word;
}
where constants.wordListSmall
is the words dictionary of random-words library.
And constants.utils.wordLengthBase
can be anything like 3,4
just don't put -1
because it will run forever.
Alternatively I would use lodash library or simple JS, to filter the words based on the String length.
This looks useful, but a problem is that it's not really well defined what lengths are even available in the dataset. I haven't looked...
On Mon, Jan 14, 2019 at 5:47 AM Michael Dobekidis notifications@github.com wrote:
I have naively implemented this by doing:
function word() { return constants.wordListSmall[randInt(constants.wordListSmall.length)]; } function randInt(lessThan) { return Math.floor(Math.random() * lessThan); }
function findWord(){ let _word = word(); while (String(_word).length <= constants.utils.wordLengthBase) { _word = word(); } return _word; }
where constants.wordListSmall is the words dictionary of random-words library. And constants.utils.wordLengthBase can be anything like 3,4 just don't put -1 because it will run forever. Alternatively I would use lodash library or simple JS, to filter the words based on the String length.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/punkave/random-words/issues/13#issuecomment-453963954, or mute the thread https://github.com/notifications/unsubscribe-auth/AAB9fVT1gHsqeIlZawwvgkfG2il1vEU_ks5vDGBDgaJpZM4Z9-0F .
--
Thomas Boutell, Chief Software Architect P'unk Avenue | (215) 755-1330 | punkave.com
running this on the console:
var max = 0;
for(var i=0;i<wordList.length;i++){
if(wordList[i].length > max){max = wordList[i].length;}
}
console.log(max);
printed 14
so that is the longest word on this library dictionary.
There could be lengths with no words less than 14, though.
On Mon, Jan 14, 2019 at 9:19 AM Michael Dobekidis notifications@github.com wrote:
running this on the console:
var max = 0; for(var i=0;i<wordList.length;i++){ if(wordList[i].length > max){max = wordList[i].length;} } console.log(max);
printed 14 so that is the longest word on this libraries dictionary.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/punkave/random-words/issues/13#issuecomment-454020000, or mute the thread https://github.com/notifications/unsubscribe-auth/AAB9feDEif791vF6wRwQI2FtsCCNA614ks5vDJHhgaJpZM4Z9-0F .
--
Thomas Boutell, Chief Software Architect P'unk Avenue | (215) 755-1330 | punkave.com
++ request for this feature. I think it would be great if this library provides a feature for getting random words with the given length
PRs (and dictionary improvements) are welcome!
main
, but wouldn't you rather get some Git practice by working on a branch, and then merging to your own main
?CHANGELOG.md
file - since other people might contribute during the same sprint cycle, add your change log message under 'UNRELEASED', not a specific version. We will add the version number when everything is approved and published on npm.Check out the suggestions that have already been made on this issue in earlier comments.
One edge case you need to worry about that is pointed out is if there aren't any words of a specific length or if the user wants ten words that are 6 letters long` and there are only four. Right now, there aren't any guardrails in place because the other options can almost always be fulfilled. Suggesting how you would take care of this either here on the issue or in the Discord would be great to get feedback and make sure you are on a good track.
Finally, please make use of the Discord to ask questions. Try to answer the questions yourself using internet resources, but don't be afraid to ask questions on the Discord about anything. We are here to help!
Thank you for library!
Is there any way for generating word with a predefined size of word length? As far as I can see, it could be implemented with minLength parameter, for example:
randomWords({minLength: 4, maxLength: 4})