Skip to content

Commit

Permalink
fix suffle
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrilgourgouillon committed Dec 3, 2023
1 parent 0e82a1f commit 2c5feed
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/services/noteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@ import { NOTES_LIST_MAX, NOTES_LIST_MIN } from "../config/constants";
import { getRandomItemFrom } from "../utils/random";
import { shuffle } from "../utils/shuffle";

export const getListOfRandomNotes = (count: number, allNotes?: Note[]): Note[] => {
export const getListOfRandomUniqueNotes = (count: number, allNotes?: Note[]): Note[] => {
const randomNotes = shuffle(allNotes ?? notes);

return randomNotes.slice(undefined, count);
};

export const getListOfRandomNotes = (count: number, allNotes?: Note[]): Note[] => {
const randomNotes: Note[] = [];
for(let i = 0; i < count; i++) {
randomNotes.push(getRandomNote(allNotes));
}
return randomNotes;
}

export const isValidNoteCountList = (count: number): boolean => {
return count >= NOTES_LIST_MIN && count <= NOTES_LIST_MAX
}

export const getRandomNote = (): Note => {
return getRandomItemFrom(notes);
export const getRandomNote = (allNotes?: Note[]): Note => {
return getRandomItemFrom(allNotes ?? notes);
};

export const getRandomNoteFromCaged = (): Caged => {
Expand Down

0 comments on commit 2c5feed

Please sign in to comment.