Skip to content

Commit

Permalink
Add the requirement that all bookmarks require distinct translations
Browse files Browse the repository at this point in the history
  • Loading branch information
tfnribeiro committed Oct 24, 2024
1 parent aba0e8f commit 24a8dd1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/exercises/assignBookmarksToExercises.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ function assignBookmarksWithLearningCycle(bookmarks, exerciseTypesList) {
return distinctContextsCount === potentialBookmarkContexts.length;
}

function _distinctTranslations(potentialBookmarks) {
let potentialBookmarkContexts = potentialBookmarks.map(
(bookmark) => bookmark.to,
);
let distinctContextsCount = new Set(potentialBookmarkContexts).size;
return distinctContextsCount === potentialBookmarkContexts.length;
}

let exerciseSequence = [];

let exercisesByCycleTask = getElementsByCycleTask(
Expand Down Expand Up @@ -109,7 +117,12 @@ function assignBookmarksWithLearningCycle(bookmarks, exerciseTypesList) {
let availableBookmarks = currentBookmarkList.length;
if (
requiredBookmarks <= availableBookmarks &&
_distinctContexts(currentBookmarkList.slice(0, requiredBookmarks))
_distinctContexts(
currentBookmarkList.slice(0, requiredBookmarks),
) &&
_distinctTranslations(
currentBookmarkList.slice(0, requiredBookmarks),
)
) {
let testedBookmarks = popNElementsFromList(
currentBookmarkList,
Expand Down

0 comments on commit 24a8dd1

Please sign in to comment.