Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface for sampling elements from an array-like object.

Hierarchy

  • Sample

Callable

  • Samples elements from an array-like object.

    throws

    must provide valid options

    throws

    size option must be less than or equal to the length of x when the replace option is false

    Parameters

    • x: ArrayLike<any>

      array-like object from which to sample

    • Optional options: Options

      function options

    Returns Array < any >

    sample

    Example

    var out = sample( [ 3, null, NaN, 'abc', function(){} ] );
    // e.g., returns [ 3, 'abc', null, 3, null ]

Index

Methods

Methods

factory

  • Returns a function to sample elements from an array-like object.

    throws

    must provide valid options

    Parameters

    Returns SamplePopFunction

    function to sample elements from an array-like object

    Example

    var fcn = sample.factory( [ 1, 2, 3, 4, 5, 6 ], {
        'seed': 232,
        'size': 2
    });
    var out = fcn();
    // e.g., returns [ 6, 4 ]
    
    out = fcn();
    // e.g., returns [ 6, 5 ]

    Example

    var fcn = sample.factory( [ 1, 2, 3, 4, 5, 6 ], {
        'seed': 474,
        'size': 3,
        'mutate': true,
        'replace': false
    });
    var out = fcn();
    // e.g., returns [ 4, 3, 6 ]
    
    out = fcn();
    // e.g., returns [ 1, 5, 2 ]
    
    out = fcn();
    // returns null

    Example

    var fcn = sample.factory( [ 0, 1 ], {
        'size': 2
    });
    
    var out = fcn();
    // e.g., returns [ 1, 1 ]
    
    out = fcn({
        'size': 10
    });
    // e.g., returns [ 0, 1, 1, 1, 0, 1, 0, 0, 1, 1 ]

    Example

    var fcn = sample.factory( [ 0, 1 ], {
        'size': 2
    });
    
    var out = fcn();
    // e.g., returns [ 1, 1 ]
    
    out = fcn({
        'replace': false
    });
    // e.g., returns [ 0, 1 ] or [ 1, 0 ]
    
    out = fcn();
    // e.g., returns [ 1, 1 ]

    Example

    var fcn = sample.factory( [ 0, 1 ], {
        'size': 2,
        'mutate': true
    });
    
    var out = fcn();
    // e.g., returns [ 1, 1 ]
    
    out = fcn({
        'replace': false
    });
    // e.g., returns [ 0, 1 ] or [ 1, 0 ]
    
    out = fcn();
    // returns null
  • Returns a function to sample elements from an array-like object.

    throws

    must provide valid options

    Parameters

    Returns SampleFunction

    function to sample elements from an array-like object

    Example

    var fcn = sample.factory({
        'seed': 232
    });
    var out = fcn( 'abcdefg' );
    // e.g., returns [ 'g', 'd', 'g', 'f', 'c', 'e', 'f' ]