-
-
Notifications
You must be signed in to change notification settings - Fork 628
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 findLastIndex
method to array/fixed-endian-factory
#3295
base: develop
Are you sure you want to change the base?
Conversation
Coverage Report
The above coverage report was generated for the changes in this PR. |
kindly give this a review @kgryte! |
Signed-off-by: Aayush Khanna <[email protected]>
@Planeshifter I've resolved the merge conflicts in this branch |
this branch should be free of any indentation errors which were made while resolving merge conflicts now. |
* @returns {boolean} boolean indicating whether a value passes a test | ||
*/ | ||
function predicate( value ) { | ||
return value % 2 === 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.
This should always evaluate to false. E.g., value < 0.0
. Otherwise, the benchmark is effectively O(1), which is not what we want.
/** | ||
* Returns the index of the last element in an array for which a predicate function returns a truthy value. | ||
* | ||
* @name findLastIndex |
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.
* @name findLastIndex | |
* @private | |
* @name findLastIndex |
var len; | ||
var i; | ||
if ( !isTypedArray( this ) ) { | ||
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) ); | ||
} | ||
if ( !isFunction( predicate ) ) { | ||
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); | ||
} | ||
buf = this._buffer; | ||
len = this._length; | ||
for ( i = len - 1; i >= 0; i-- ) { |
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 len; | |
var i; | |
if ( !isTypedArray( this ) ) { | |
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) ); | |
} | |
if ( !isFunction( predicate ) ) { | |
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); | |
} | |
buf = this._buffer; | |
len = this._length; | |
for ( i = len - 1; i >= 0; i-- ) { | |
var i; | |
if ( !isTypedArray( this ) ) { | |
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) ); | |
} | |
if ( !isFunction( predicate ) ) { | |
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); | |
} | |
buf = this._buffer; | |
for ( i = this._length - 1; i >= 0; i-- ) { |
The local variable is not necessary in this case, as we are only accessing _length
once.
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.
@aayush0325 Thanks for working on this. Left a few comments. Once resolved, this should be ready for merge, provided that the merge conflicts are resolved.
Signed-off-by: Aayush Khanna <[email protected]>
Resolves #3144
Description
This pull request:
findLastIndex
method toarray/fixed-endian-factory
README.md
with appropriate documentation.Related Issues
This pull request:
findLastIndex
method toarray/fixed-endian-factory
#3144Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers