Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions lib/node_modules/@stdlib/utils/tabulate-by/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,26 @@ The returned frequency table is an `array` of `arrays`. Each sub-array correspon
<!-- eslint no-undef: "error" -->

```javascript
var randu = require( '@stdlib/random/base/randu' );
var floor = require( '@stdlib/math/base/special/floor' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var take = require( '@stdlib/array/take' );
var tabulateBy = require( '@stdlib/utils/tabulate-by' );

var vals;
var indices;
var arr;
var out;
var i;
var j;

function indicator( value ) {
return value[ 0 ];
}

vals = [ 'beep', 'boop', 'foo', 'bar', 'woot', 'woot' ];

// Generate a random collection...
arr = [];
for ( i = 0; i < 100; i++ ) {
j = floor( randu()*vals.length );
arr.push( vals[ j ] );
}
// Generate a list of random indices:
indices = discreteUniform( 100, 0, vals.length - 1 );

// Create a random collection by picking elements at the generated indices:
arr = take( vals, indices );

// Generate a frequency table:
out = tabulateBy( arr, indicator );
Expand Down
18 changes: 8 additions & 10 deletions lib/node_modules/@stdlib/utils/tabulate-by/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,26 @@

'use strict';

var randu = require( '@stdlib/random/base/randu' );
var floor = require( '@stdlib/math/base/special/floor' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var take = require( '@stdlib/array/take' );
var tabulateBy = require( './../lib' );

var vals;
var indices;
var arr;
var out;
var i;
var j;

function indicator( value ) {
return value[ 0 ];
}

vals = [ 'beep', 'boop', 'foo', 'bar', 'woot', 'woot' ];

// Generate a random collection...
arr = [];
for ( i = 0; i < 100; i++ ) {
j = floor( randu()*vals.length );
arr.push( vals[ j ] );
}
// Generate a list of random indices:
indices = discreteUniform( 100, 0, vals.length - 1 );

// Create a random collection by picking elements at the generated indices:
arr = take( vals, indices );

// Generate a frequency table:
out = tabulateBy( arr, indicator );
Expand Down