We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
What about adding a casual.random_element(array, x) to return x random elements from array?
casual.random_element(array, x)
x
array
Under the hood code could look like:
function getRandomArrayElements (array, count, startIndex, endIndex) { if (Array.isArray(array) === false) throw new Error('Invalid array object') if (startIndex < 0 || startIndex > array.length - 1) throw new Error('Invalid startIndex value') if (endIndex < 0 || endIndex > array.length - 1) throw new Error('Invalid endIndex value') if (count < startIndex || count > (endIndex - startIndex) + 1) throw new Error('Invalid count value') var resultList = [] var temp, randomIndex while (count > 0) { randomIndex = chooseRandomNumer(startIndex, endIndex) temp = array[randomIndex] array[randomIndex] = array[endIndex] array[endIndex] = temp resultList.push(temp) count-- endIndex-- } return resultList }
Just submitting the idea for validation, will come back with a PR if validated.
The text was updated successfully, but these errors were encountered:
There is random_element function, not sure if random_elements is necessary. But if more other people would find it useful we can add it.
random_elements
Sorry, something went wrong.
I use it with my ORM (sequelize) to create data seeders. It's nice to have when you need to create random N:M associations.
No branches or pull requests
What about adding a
casual.random_element(array, x)
to returnx
random elements fromarray
?Under the hood code could look like:
Just submitting the idea for validation, will come back with a PR if validated.
The text was updated successfully, but these errors were encountered: