-
-
Notifications
You must be signed in to change notification settings - Fork 745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add toSorted
method to array/fixed-endian-factory
#3302
base: develop
Are you sure you want to change the base?
feat: add toSorted
method to array/fixed-endian-factory
#3302
Conversation
Coverage Report
The above coverage report was generated for the changes in this PR. |
toSorted
method to array/fixed-endian-factorytoSorted
method to array/fixed-endian-factory
} | ||
} | ||
b.toc(); | ||
if ( !isTypedArray( out ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a valid check, as out
is not an actual typed array instance.
} | ||
} | ||
b.toc(); | ||
if ( !isTypedArray( out ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment.
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) ); | ||
} | ||
if ( arguments.length === 0 ) { | ||
compareFcn = function defaultCompareFcn( a, b ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't typically use function expressions, only declarations. I suggest refactoring accordingly. It is also not necessary to have this function in a nested scope and can be lifted to the top most scope.
minVal = obuf[ GETTER ]( i * BYTES_PER_ELEMENT, this._isLE ); | ||
for ( j = i+1; j < len; j++ ) { | ||
val = obuf[ GETTER ]( j * BYTES_PER_ELEMENT, this._isLE ); | ||
if ( compareFcn( minVal, val ) > 0 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than rolling your own sort function, copy to a temporary generic array, sort using the built-in #.sort
method, and then copy to an output array.
expected = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; | ||
out = arr.toSorted( compareFcn ); | ||
values = []; | ||
fcn(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than use fcn
to generate a values array, just use array/base/assert/has-same-values
and compare to an expected Float64ArrayFE
.
expected = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; | ||
out = arr.toSorted(); | ||
values = []; | ||
fcn(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment.
var arr = new Float64ArrayFE( 'little-endian', [ 3.0, 1.0, 2.0 ] ); | ||
// returns <Float64ArrayFE> | ||
|
||
var out=arr.toSorted( compareFcn ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var out=arr.toSorted( compareFcn ); | |
var out = arr.toSorted( compareFcn ); |
You need spaces around operators here and below.
var out=arr.toSorted( compareFcn ); | ||
// returns <Float64ArrayFE> | ||
|
||
var v=out.get(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var v=out.get(0); | |
var v = out.get( 0 ); |
Spaces around arguments here and below.
@@ -607,6 +607,39 @@ var idx = arr.lastIndexOf( 5.0 ); | |||
// returns -1 | |||
``` | |||
|
|||
<a name="method-toSorted"></a> | |||
|
|||
#### TypedArrayFE.prototype.toSorted( compareFcn ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compareFcn
is optional.
@@ -607,6 +607,39 @@ var idx = arr.lastIndexOf( 5.0 ); | |||
// returns -1 | |||
``` | |||
|
|||
<a name="method-toSorted"></a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should be inserted into the docs such that methods are listed in alphabetical order.
* @throws {TypeError} first argument must be a function | ||
* @returns {TypedArray} sorted array | ||
*/ | ||
setReadOnly( TypedArray.prototype, 'toSorted', function sort( compareFcn ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Insert methods in alphabetical order.
- update method logic and insert it into correct place in both main.js and readme - update type checking in benchmarks - use hasSameValues in test file
@kgryte @Planeshifter I have applyed all changes you've suggested in this PR and also in #3298 |
@kgryte may you give it a review? |
Resolves #3160
Description
This pull request:
toSorted
method to @stdlib/array/fixed-endian-factory.Related Issues
This pull request:
toSorted
method toarray/fixed-endian-factory
#3160Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers