time-to-botec/squiggle/node_modules/@stdlib/ndarray/base/wrap-index/README.md
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00

2.3 KiB

Wrap Index

Wrap an index on the interval [0,max].

Usage

var wrapIndex = require( '@stdlib/ndarray/base/wrap-index' );

wrapIndex( idx, max )

Wrap an index on the interval [0,max].

var idx = wrapIndex( 2, 10 );
// returns 2

idx = wrapIndex( -5, 10 );
// returns 6

idx = wrapIndex( 15, 10 );
// returns 4

Examples

var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var wrapIndex = require( '@stdlib/ndarray/base/wrap-index' );

var idx;
var out;
var i;

for ( i = 0; i < 100; i++ ) {
    idx = discreteUniform( -20, 20 );
    out = wrapIndex( idx, 9 );
    console.log( '%d => [%d,%d] => %d', idx, 0, 9, out );
}