-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request - generate words starting with letter #17
Comments
I would like that aswell. |
How to work on this issue
Code suggestions for this issueIf you look at the One edge case you need to worry about is if there aren't any words starting with that letter or if the user wants ten words starting with 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! |
I can do a pull request, but the gist of my change would be: function generateRandomWordStartingWith(startingLetter){
const filteredList = wordList.filter(word => word.startsWith(startingLetter));
return filteredList[randInt(filteredList.length)];
} Notes on code suggestions:
Let me know if it's better if we talk about this on discord or on an actual PR. Thanks for working on this awesome library btw |
Hi @ldd |
Is this issue still open? Can I attempt it? |
I haven't heard anything from @idd since the last message, so I guess they are not going to work on it. Read the notes and give it a try! Let me know in our Discord or here when you need a code review. |
Are the users supposed to specify the amount of words to be generated along with the starting letter? Or should I print all the letters starting with the specified letter? |
This would be an add-on option. So a user should be able to specify that they want 5 words all starting with 'a', for example. But, they should also be able to leave off how many need to be returned if they only want one. |
Hi @BoDonkey , here's the link to index.js file of my attempt at the issue: https://github.com/Suyash699/random-words/blob/main/index.js |
Hi @Suyash699, Thanks for trying this! At first glance, your function to filter the words looks reasonable. Although I would say that |
One thing I can see is that "toLowerCase" is a method, but you are not invoking it, so you are comparing functions themselves, not strings. I suggest that you open a PR with your current attempt and mark it as draft if it's not ready, so it's easier to give feedback. |
Hi @BoDonkey, will this work? :
So basically, added the previous function in a ternary operator that checks if the given letter falls in the unicode range of a-z or not, and if yes, then checks whether it exists in the As for the "toLowerCase" problem, I have corrected that as well. I'm considering making a PR as well @boutell |
@Suyash699 - Check out how the other options in the repo work. Basically, the user is passing parameters to the main function. Those parameters dictate what will be returned to the user. For example, if the user makes a request like if(options === undefined) {
return word();
} That conditional is looking at whether the user passed any arguments. If they didn't then return a single random word. You need to fashion your code in a similar way. You need to change what is returned to the user after checking if the option you designate is there and has a certain value. Take a look at the |
Hey @BoDonkey, I have been playing around with this module for a while now & I have a few questions:
|
Hi @bhaveshittadwar, 1 ) Yes, we want the user to be able to pass a key like There should be tests for any of those three returning early. |
@UnKnoWn-Consortium PRs always welcome! Thanks. |
Would love to see an option that will generate random words starting with a specific letter (parameter a-z).
Something like
The text was updated successfully, but these errors were encountered: