@@ -28,6 +28,7 @@ var isCollection = require( '@stdlib/assert-is-collection' );
2828var isArrayBuffer = require ( '@stdlib/assert-is-arraybuffer' ) ;
2929var isObject = require ( '@stdlib/assert-is-object' ) ;
3030var isArray = require ( '@stdlib/assert-is-array' ) ;
31+ var isStringArray = require ( '@stdlib/assert-is-string-array' ) . primitives ;
3132var isString = require ( '@stdlib/assert-is-string' ) . isPrimitive ;
3233var isFunction = require ( '@stdlib/assert-is-function' ) ;
3334var isComplexLike = require ( '@stdlib/assert-is-complex-like' ) ;
@@ -2491,6 +2492,59 @@ setReadOnly( Complex64Array.prototype, 'subarray', function subarray( begin, end
24912492 return new this . constructor ( buf . buffer , offset , ( len < 0 ) ? 0 : len ) ;
24922493} ) ;
24932494
2495+ /**
2496+ * Serializes an array as a locale-specific string.
2497+ *
2498+ * @name toLocaleString
2499+ * @memberof Complex64Array.prototype
2500+ * @type {Function }
2501+ * @param {(string|Array<string>) } [locales] - locale identifier(s)
2502+ * @param {Object } [options] - configuration options
2503+ * @throws {TypeError } `this` must be a complex number array
2504+ * @throws {TypeError } first argument must be a string or an array of strings
2505+ * @throws {TypeError } options argument must be an object
2506+ * @returns {string } string representation
2507+ *
2508+ * @example
2509+ * var arr = new Complex64Array( 2 );
2510+ *
2511+ * arr.set( [ 1.0, 1.0 ], 0 );
2512+ * arr.set( [ 2.0, 2.0 ], 1 );
2513+ *
2514+ * var str = arr.toLocaleString();
2515+ * // returns '1 + 1i,2 + 2i'
2516+ */
2517+ setReadOnly ( Complex64Array . prototype , 'toLocaleString' , function toLocaleString ( locales , options ) {
2518+ var opts ;
2519+ var loc ;
2520+ var out ;
2521+ var buf ;
2522+ var i ;
2523+ if ( ! isComplexArray ( this ) ) {
2524+ throw new TypeError ( 'invalid invocation. `this` is not a complex number array.' ) ;
2525+ }
2526+ if ( arguments . length === 0 ) {
2527+ loc = [ ] ;
2528+ } else if ( isString ( locales ) || isStringArray ( locales ) ) {
2529+ loc = locales ;
2530+ } else {
2531+ throw new TypeError ( 'invalid argument. First argument must be a string or an array of strings. Value: `' + locales + '`.' ) ;
2532+ }
2533+ if ( arguments . length < 2 ) {
2534+ opts = { } ;
2535+ } else if ( isObject ( options ) ) {
2536+ opts = options ;
2537+ } else {
2538+ throw new TypeError ( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' ) ;
2539+ }
2540+ buf = this . _buffer ;
2541+ out = [ ] ;
2542+ for ( i = 0 ; i < this . _length ; i ++ ) {
2543+ out . push ( getComplex64 ( buf , i ) . toLocaleString ( loc , opts ) ) ;
2544+ }
2545+ return out . join ( ',' ) ;
2546+ } ) ;
2547+
24942548/**
24952549* Returns a new typed array containing the elements in reversed order.
24962550*
0 commit comments