refactor: extract shuffleArray to src/utils
This commit is contained in:
		
							parent
							
								
									4da6e08448
								
							
						
					
					
						commit
						71ab64343f
					
				|  | @ -1,6 +1,7 @@ | |||
| /* Imports */ | ||||
| import fs from "fs"; | ||||
| 
 | ||||
| import { shuffleArray } from "../../../utils"; | ||||
| import { pgRead } from "../../database/pg-wrapper"; | ||||
| 
 | ||||
| /* Definitions */ | ||||
|  | @ -13,15 +14,6 @@ let getQualityIndicators = (question) => | |||
|     .map((entry) => `${entry[0]}: ${entry[1]}`) | ||||
|     .join("; "); | ||||
| 
 | ||||
| let shuffleArray = (array) => { | ||||
|   // See: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
 | ||||
|   for (let i = array.length - 1; i > 0; i--) { | ||||
|     const j = Math.floor(Math.random() * (i + 1)); | ||||
|     [array[i], array[j]] = [array[j], array[i]]; | ||||
|   } | ||||
|   return array; | ||||
| }; | ||||
| 
 | ||||
| /* Body */ | ||||
| 
 | ||||
| let main = async () => { | ||||
|  |  | |||
							
								
								
									
										8
									
								
								src/utils.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/utils.ts
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,8 @@ | |||
| export const shuffleArray = <T>(array: T[]): T[] => { | ||||
|   // See: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
 | ||||
|   for (let i = array.length - 1; i > 0; i--) { | ||||
|     const j = Math.floor(Math.random() * (i + 1)); | ||||
|     [array[i], array[j]] = [array[j], array[i]]; | ||||
|   } | ||||
|   return array; | ||||
| }; | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user