shuffleInPlace
配列 arr の要素をランダムに並べ替え、変更後の元配列への参照を返します。
パラメータ notFixedPoint は、シャッフル後にすべての要素が元の位置から移動することを強制するかどうかを制御します。
false(デフォルト)の場合、Fisher-Yates アルゴリズムを使用します(要素は元の位置に残る可能性があります)。trueの場合、Sattolo アルゴリズムを使用します(すべての要素が元の位置に残らないことを保証します)。
Added in v0.1.0
Usage
ts
import { shuffleInPlace } from 'parsnip-kit'
const original = [1, 2, 3, 4, 5]
const res0 = shuffleInPlace(original) // It would be [3, 2, 4, 1, 5]
const res1 = shuffleInPlace(original, true) // It would be [3, 4, 2, 5, 1]
res0 === original // true
res1 === original // trueAPI
Type Parameter
| Arg | Type | Description |
|---|---|---|
T | | 入力配列の要素型 |
Arguments
| Arg | Type | Optional | Default | Description |
|---|---|---|---|---|
arr | T[] | false | undefined | シャッフル対象の入力配列 |
noFixedPoint | Boolean | true | false | 全要素を元の位置から移動させるか否か |
Returns
| Type |
|---|
T[] |