Skip to content

Commit cc4f221

Browse files
committed
Use base utility
1 parent a442617 commit cc4f221

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

lib/node_modules/@stdlib/array/linspace/lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232

3333
// MODULES //
3434

35-
var linspace = require( './linspace.js' );
35+
var main = require( './main.js' );
3636

3737

3838
// EXPORTS //
3939

40-
module.exports = linspace;
40+
module.exports = main;

lib/node_modules/@stdlib/array/linspace/lib/linspace.js renamed to lib/node_modules/@stdlib/array/linspace/lib/main.js

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
2424
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var gen = require( '@stdlib/array/base/linspace' );
2627

2728

2829
// MAIN //
@@ -43,11 +44,6 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' );
4344
* // returns [ 0, 20, 40, 60, 80, 100 ]
4445
*/
4546
function linspace( x1, x2, len ) {
46-
var arr;
47-
var end;
48-
var tmp;
49-
var d;
50-
var i;
5147
if ( !isNumber( x1 ) || isnan( x1 ) ) {
5248
throw new TypeError( 'invalid argument. Start must be numeric. Value: `' + x1 + '`.' );
5349
}
@@ -56,28 +52,10 @@ function linspace( x1, x2, len ) {
5652
}
5753
if ( arguments.length < 3 ) {
5854
len = 100;
59-
} else {
60-
if ( !isNonNegativeInteger( len ) ) {
61-
throw new TypeError( 'invalid argument. Length must be a nonnegative integer. Value: `' + len + '`.' );
62-
}
63-
if ( len === 0 ) {
64-
return [];
65-
}
55+
} else if ( !isNonNegativeInteger( len ) ) {
56+
throw new TypeError( 'invalid argument. Length must be a nonnegative integer. Value: `' + len + '`.' );
6657
}
67-
// Calculate the increment:
68-
end = len - 1;
69-
d = ( x2-x1 ) / end;
70-
71-
// Build the output array...
72-
arr = [];
73-
tmp = x1;
74-
arr.push( tmp );
75-
for ( i = 1; i < end; i++ ) {
76-
tmp += d;
77-
arr.push( tmp );
78-
}
79-
arr.push( x2 );
80-
return arr;
58+
return gen( x1, x2, len );
8159
}
8260

8361

0 commit comments

Comments
 (0)