-
-
Notifications
You must be signed in to change notification settings - Fork 578
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 values
method to array/fixed-endian-factory
#3294
base: develop
Are you sure you want to change the base?
Conversation
The `values()` method was added to the typed array prototype to allow iteration over the array's values. This method returns an iterator, which can be used in a `for...of` loop or with `next()` calls to access each value in the array sequentially. This change simplifies the process of iterating over typed arrays, ensuring that code interacting with them is more readable and easier to maintain. Fixes: stdlib-js#123
Coverage Report
The above coverage report was generated for the changes in this PR. |
Please change the PR title to |
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
iter = arr.values(); | ||
|
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.
* @throws {TypeError} `this` must be a typed array instance | ||
* @returns {Object} iterator for array elements | ||
*/ | ||
setReadOnly(TypedArray.prototype, 'values', function values() { |
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.
setReadOnly(TypedArray.prototype, 'values', function values() { | |
setReadOnly( TypedArray.prototype, 'values', function values() { |
var buf = this._buffer; | ||
var len = this._length; | ||
|
||
if (!isTypedArray(this)) { |
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.
if (!isTypedArray(this)) { | |
if ( !isTypedArray( this ) ) { |
throw new TypeError(format('invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[dtype[0]], CTOR_NAME)); | ||
} | ||
|
||
iterator = { | ||
'next': function next() { | ||
if (index < len) { | ||
value = buf[GETTER](index * BYTES_PER_ELEMENT, isLE); | ||
index += 1; | ||
return { | ||
'value': value, | ||
'done': false | ||
}; | ||
} | ||
return { | ||
'done': true | ||
}; | ||
} | ||
}; | ||
|
||
iterator[Symbol.iterator] = function iterator() { | ||
return this; | ||
}; | ||
|
||
return iterator; | ||
}); | ||
|
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.
Please add the spaces under the every parans.. same way i have suggested
t.end(); | ||
}); | ||
|
||
tape( 'the `values` method returns an iterator function', function test( t ) { |
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.
Test case like this is missing
var iterator; | ||
var result; | ||
var ctor = factory( 'float64' ); | ||
var arr = new ctor( 'little-endian', [1.0, 2.0, 3.0, 4.0, 5.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 arr = new ctor( 'little-endian', [1.0, 2.0, 3.0, 4.0, 5.0] ); | |
var arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); |
var iterator; | ||
var result; | ||
var ctor = factory( 'float64' ); | ||
var arr = new ctor( 'little-endian', [10.5, 20.5, 30.5] ); |
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.
missing spaces in square braces [ ... ]
var values = []; | ||
var value; | ||
var ctor = factory( 'float64' ); | ||
var arr = new ctor( 'little-endian', [1.0, 2.0, 3.0, 4.0, 5.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.
missing spaces in square braces [ ... ]
values.push( value ); | ||
} | ||
|
||
t.deepEqual( values, [1.0, 2.0, 3.0, 4.0, 5.0], 'correctly iterates over values' ); |
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.
missing spaces in square braces [ ... ] .
please do same for all
@MeastroZI Thanks for the review , i have made the required changes. |
values
method to array/fixed-endian-factory
The
values()
method was added to the typed array prototype to allow iteration over the array's values. This method returns an iterator, which can be used in afor...of
loop or withnext()
calls to access each value in the array sequentially. This change simplifies the process of iterating over typed arrays, ensuring that code interacting with them is more readable and easier to maintain.Fixes: #3161
Resolves #3161
Description
This pull request:
add values method to @stdlib/array/fixed-endian-factory
Related Issues
This pull request:
values
method toarray/fixed-endian-factory
#3161Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers