Skip to content

Latest commit

 

History

History
143 lines (92 loc) · 3.83 KB

File metadata and controls

143 lines (92 loc) · 3.83 KB

gjoinBetween

Return a string by joining one-dimensional ndarray elements using a specified separator for each pair of consecutive elements.

Usage

var gjoinBetween = require( '@stdlib/blas/ext/base/ndarray/gjoin-between' );

gjoinBetween( arrays )

Returns a string by joining one-dimensional ndarray elements using a specified separator for each pair of consecutive elements.

var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );

var xbuf = [ 1, 2, 3, 4 ];
var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );

var prefix = scalar2ndarray( 'op: ', {
    'dtype': 'generic'
});

var suffix = scalar2ndarray( '', {
    'dtype': 'generic'
});

var sbuf = [ ' + ', ' - ', ' != ' ];
var separators = new ndarray( 'generic', sbuf, [ 3 ], [ 1 ], 0, 'row-major' );

var out = gjoinBetween( [ x, prefix, suffix, separators ] );
// returns 'op: 1 + 2 - 3 != 4'

The function has the following parameters:

  • arrays: array-like object containing the following ndarrays:

    • a one-dimensional input ndarray.
    • a zero-dimensional ndarray containing a prefix string.
    • a zero-dimensional ndarray containing a suffix string.
    • a one-dimensional ndarray containing separator strings.

Notes

  • If the input ndarray is empty, the function returns the prefix and suffix joined together.
  • The separators ndarray is assumed to have at least N-1 elements (i.e., equal to the number of "gaps" between consecutive elements), where N is the number of elements in the input ndarray.
  • If an array element is either null or undefined, the function serializes the element as an empty string.

Examples

var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var filled = require( '@stdlib/array/base/filled' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var gjoinBetween = require( '@stdlib/blas/ext/base/ndarray/gjoin-between' );

var xbuf = discreteUniform( 10, -100, 100, {
    'dtype': 'generic'
});
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
console.log( ndarray2array( x ) );

var prefix = scalar2ndarray( '[ ', {
    'dtype': 'generic'
});

var suffix = scalar2ndarray( ' ]', {
    'dtype': 'generic'
});

var sbuf = filled( ' | ', xbuf.length - 1 );
var separators = new ndarray( 'generic', sbuf, [ sbuf.length ], [ 1 ], 0, 'row-major' );

var out = gjoinBetween( [ x, prefix, suffix, separators ] );
console.log( out );