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,CACA,OAAO,mBAAmB,EAAK,EAGnC,IADA,KACQ,EAAgB,EAAS,EAAS,IACtC,IAGJ,OAAO,EAAO,KAAK,IACf,MAAM,EAAc,EAAQ,WAAW,GAAU,EAAM,OAAS,EAAE,OAClE,OAAO,EAAQ,EAAY,GAEnC,CAEA,QAAQ,UAAY,UACpB,QAAQ,gBAAkB","file":"/npm/gift-exchange@4.0.4/dist/giftexchange.cjs.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/gift-exchange@4.0.4/dist/giftexchange.cjs.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nfunction shuffle(array) {\n    let i = array.length;\n    let j;\n    while (i !== 0) {\n        j = Math.floor(Math.random() * i);\n        i -= 1;\n        const swap = array[i];\n        array[i] = array[j];\n        array[j] = swap;\n    }\n    return array;\n}\nfunction validateMatches(a, b, exclusions = []) {\n    if (a.length !== b.length)\n        return false;\n    // pA - person a, pB - person b\n    return a.every((pA, i) => {\n        const pB = b[i];\n        // skip matches that are the same name\n        if (pA.name === pB.name)\n            return false;\n        // skip matches that are in the same group, if groups are defined\n        if ((pA.group || pB.group) && pA.group === pB.group)\n            return false;\n        return (exclusions\n            // filter to exclusions of subjects that match pA\n            .filter((exclusion) => pA[exclusion.type] === exclusion.subject)\n            // reject pB if they have an excludedType of excludedValue\n            .every((exclusion) => pB[exclusion.excludedType] !== exclusion.excludedSubject));\n    });\n}\nfunction calculate(people, exclusionsOrOptions) {\n    var _a, _b;\n    if (people.length < 2) {\n        return people.slice(0);\n    }\n    let exclusions;\n    let timeout = 1000;\n    if (Array.isArray(exclusionsOrOptions)) {\n        exclusions = exclusionsOrOptions;\n    }\n    else {\n        exclusions = (_a = exclusionsOrOptions === null || exclusionsOrOptions === void 0 ? void 0 : exclusionsOrOptions.exclusions) !== null && _a !== void 0 ? _a : [];\n        timeout = (_b = exclusionsOrOptions === null || exclusionsOrOptions === void 0 ? void 0 : exclusionsOrOptions.timeout) !== null && _b !== void 0 ? _b : 1000;\n    }\n    let buffer1 = [];\n    let buffer2 = [];\n    // https://www.youtube.com/watch?v=5kC5k5QBqcc\n    const shuffleAndSlide = () => {\n        const shuffled = shuffle(people.slice());\n        buffer1 = shuffled.slice(0);\n        buffer2 = shuffled.slice(0);\n        // slide each element over by one on buffer2.\n        // we check the people array before this, and are mutating buffers for\n        // performance, so it is safe to use a non-null assertion here.\n        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n        buffer2.push(buffer2.shift());\n    };\n    const startTime = Date.now();\n    const testDerangement = (...args) => {\n        // prevent infinite loops when no combination is found\n        if (Date.now() - startTime > timeout) {\n            const error = new Error(\"No combinations found\");\n            error.name = \"GiftExchangeError\";\n            throw error;\n        }\n        return validateMatches(...args);\n    };\n    shuffleAndSlide();\n    while (!testDerangement(buffer1, buffer2, exclusions)) {\n        shuffleAndSlide();\n    }\n    // map back to the order of the given person argument\n    return people.map((p) => {\n        const personIndex = buffer1.findIndex((match) => match.name === p.name);\n        return buffer2[personIndex];\n    });\n}\n\nexports.calculate = calculate;\nexports.validateMatches = validateMatches;\n\n"]}