Function shuffle

  • Namespace

    ArrayUtils

    Shuffles the elements of an array randomly.

    Type Parameters

    • T

      The type of elements in the array.

    Parameters

    • array: T[]

      The array to be shuffled.

    Returns T[]

    A new array with the elements randomly shuffled.

    Example

    const numbers = [1, 2, 3, 4, 5];
    const shuffledNumbers = shuffleArray(numbers);
    console.log(shuffledNumbers); // Output: [3, 5, 1, 2, 4] (randomly shuffled)

    Example

    const names = ['Alice', 'Bob', 'Charlie', 'David'];
    const shuffledNames = shuffleArray(names);
    console.log(shuffledNames); // Output: ['Bob', 'Charlie', 'Alice', 'David'] (randomly shuffled)

Generated using TypeDoc