(arr: T[], num?: number)
| 2 | * Array random slice with items count |
| 3 | */ |
| 4 | export function randomSlice<T = any>(arr: T[], num?: number): T[] { |
| 5 | if (!num || num >= arr.length) { |
| 6 | return arr.slice(); |
| 7 | } |
| 8 | const index = Math.floor(Math.random() * arr.length); |
| 9 | const a: T[] = []; |
| 10 | for (let i = 0, j = index; i < num; i++) { |
| 11 | a.push(arr[j++]); |
| 12 | if (j === arr.length) { |
| 13 | j = 0; |
| 14 | } |
| 15 | } |
| 16 | return a; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Remove one exists element from an array |
no outgoing calls
no test coverage detected
searching dependent graphs…