|
1 | 1 | // eslint-disable-next-line import/no-unresolved |
2 | 2 | import latinSquare from '@quentinroy/latin-square'; |
| 3 | +import isEqual from 'lodash.isequal'; |
3 | 4 | import { ComponentBlock, DynamicBlock, StudyConfig } from '../parser/types'; |
4 | 5 | import { Sequence } from '../store/types'; |
5 | 6 | import { isDynamicBlock } from '../parser/utils'; |
@@ -57,7 +58,7 @@ function _componentBlockToSequence( |
57 | 58 | for (let i = 0; i < computedComponents.length; i += 1) { |
58 | 59 | const curr = computedComponents[i]; |
59 | 60 | if (typeof curr !== 'string' && !Array.isArray(curr)) { |
60 | | - const index = order.components.indexOf(curr); |
| 61 | + const index = order.components.findIndex((c) => isEqual(c, curr)); |
61 | 62 | computedComponents[i] = _componentBlockToSequence(curr, latinSquareObject, `${path}-${index}`) as unknown as ComponentBlock; |
62 | 63 | } |
63 | 64 | } |
@@ -122,7 +123,7 @@ function componentBlockToSequence( |
122 | 123 | return _componentBlockToSequence(orderCopy, latinSquareObject, 'root'); |
123 | 124 | } |
124 | 125 |
|
125 | | -function _createRandomOrders(order: StudyConfig['sequence'], paths: string[], path: string, index = 0) { |
| 126 | +function _createRandomOrders(order: StudyConfig['sequence'], paths: string[], path: string, index: number) { |
126 | 127 | const newPath = path.length > 0 ? `${path}-${index}` : 'root'; |
127 | 128 | if (order.order === 'latinSquare') { |
128 | 129 | paths.push(newPath); |
@@ -162,7 +163,8 @@ function generateLatinSquare(config: StudyConfig, path: string) { |
162 | 163 | }); |
163 | 164 |
|
164 | 165 | const options = (locationInSequence as ComponentBlock).components.map((c: unknown, i: number) => (typeof c === 'string' ? c : `_componentBlock${i}`)); |
165 | | - const newSquare: string[][] = latinSquare<string>(options.sort(() => 0.5 - Math.random()), true); |
| 166 | + shuffle(options); |
| 167 | + const newSquare: string[][] = latinSquare<string>(options, true); |
166 | 168 | return newSquare; |
167 | 169 | } |
168 | 170 |
|
|
0 commit comments