diff options
| author | Dhravya Shah <[email protected]> | 2024-07-23 23:33:11 -0500 |
|---|---|---|
| committer | Dhravya Shah <[email protected]> | 2024-07-23 23:33:11 -0500 |
| commit | 568531f3236801f192549e44283a4f1a19ff2f9e (patch) | |
| tree | 35720f9e0a8b886beb938f7dc6b7a17da3f871a4 /apps/web/lib | |
| parent | Merge pull request #137 from supermemoryai/pro-mode (diff) | |
| download | supermemory-568531f3236801f192549e44283a4f1a19ff2f9e.tar.xz supermemory-568531f3236801f192549e44283a4f1a19ff2f9e.zip | |
added recommended items
Diffstat (limited to 'apps/web/lib')
| -rw-r--r-- | apps/web/lib/utils.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/apps/web/lib/utils.ts b/apps/web/lib/utils.ts new file mode 100644 index 00000000..98ec6e98 --- /dev/null +++ b/apps/web/lib/utils.ts @@ -0,0 +1,23 @@ +export function getRandomSentences(fullQuery: string): string { + // Split the fullQuery into sentences + const sentences = fullQuery.match(/[^.!?]+[.!?]+/g) || []; + + // Function to get a random integer between min and max + function getRandomInt(min: number, max: number): number { + return Math.floor(Math.random() * (max - min)) + min; + } + + let selectedSentences = ""; + let totalCharacters = 0; + + // Select random sentences until totalCharacters is at least 1000 + while (totalCharacters < 1000 && sentences.length > 0) { + const randomIndex = getRandomInt(0, sentences.length); + const sentence = sentences[randomIndex]; + selectedSentences += sentence; + totalCharacters += sentence?.length || 0; + sentences.splice(randomIndex, 1); // Remove the selected sentence from the array + } + + return selectedSentences; +} |