-
Notifications
You must be signed in to change notification settings - Fork 2
add sorting for results output in expand(), expandAll() and expandN(), #82
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
Comments
Hi Ayoub, Thanks for your feedback! I'm so glad to hear this library has been helpful. I like your suggestion for supporting output in a non-random order. This was actually the original behavior but I didn't think it was useful, so I implemented the randomness. Hearing that an option for non-random order would be valuable to someone is helpful for prioritizing my effort. Conceptually I've already solved this problem in the unit tests, where I stub the randomization logic to make the tests deterministic. regex-to-strings/packages/regex-to-strings/src/pattern.spec.ts Lines 99 to 112 in f4d5a03
I'll need to think about how best to expose this behavior. My first thought is a sub-directory like // These functions output in random order.
import { expand, expandN, expandAll } from 'regex-to-strings';
// These functions output in sorted order.
import { expand, expandN, expandAll } from 'regex-to-strings/sorted'; similar to how Node.js has If there's a different API that you think would be more intuitive, please let me know! Otherwise I will try to work on this over the weekend. |
Hi Drew. Thanks for your answer. I found the sub-directory idea is good. but it can be more perfect to add optional argument for sorting or filtering results. something like this : import { expand, expandN, expandAll } from 'regex-to-strings';
const regex = '[a-e][0-5]';
const expander = expand(regex,{sort: "asc"}); // asc or desc or if I want to do some filtering, like this import { expand, expandN, expandAll } from 'regex-to-strings';
const regex = '[a-e][0-5]';
const expander = expand(regex,(str) => str.endsWith("am") ); // or any other filtreing critea. Looking forward to see and review your next commits. |
Uh oh!
There was an error while loading. Please reload this page.
Hey Drew , I hope that you're doing well.
Thank you for your incredible working. I use your library for a small time ago, I found it really usefull and helpful.
Otherwise, for a use case, I need to generate all the possible combinations of letters and numbers. and I see that the results is random and it is not sorted. I need to sort them by my own and that cost memory and time to do this with javascript native sorting function.
For example
in this small example I have just 30 examples ,
If I use expandN , it will give me a randomize order
I tried to use a workaround method using sort() and slice() like this
But this is not practical, imagine I have millions of results, It will cost time and ressource to do this, and causing a memory leak in javascript.
It is better to add sorting for expand, expandAll() and expandN().
I don't know if already exists, please to add this feature.
otherwise, You can give me a clue how I can add it in the library and contribute with you.
My Best.
The text was updated successfully, but these errors were encountered: