Skip to content
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

Implement findLast & findLastIndex on TypedArray's #3100

Closed
dirkdev98 opened this issue Jul 3, 2023 · 3 comments · Fixed by #3135
Closed

Implement findLast & findLastIndex on TypedArray's #3100

dirkdev98 opened this issue Jul 3, 2023 · 3 comments · Fixed by #3135
Assignees
Labels
enhancement New feature or request

Comments

@dirkdev98
Copy link
Contributor

dirkdev98 commented Jul 3, 2023

ECMASCript feature

Implement missing %TypedArray%.prototype.findLast ( predicate [ , thisArg ] ) and Array.prototype.findLastIndex ( predicate [ , thisArg ] ) features.

Implementing these should fix most of the remaining test262 tests with feature array-find-from-last.

Example code

// From test/built-ins/TypedArray/prototype/findLastIndex/return-index-predicate-result-is-true.js

var sample = new Int32Array([39, 3, 9]);
var called = 0;

var result = sample.findLastIndex(function() {
  called++;
  return true;
});

assert.sameValue(result, 2, "returned true on sample[2]");
assert.sameValue(called, 1, "predicate was called once");
@dirkdev98 dirkdev98 added the enhancement New feature or request label Jul 3, 2023
@dirkdev98
Copy link
Contributor Author

dirkdev98 commented Jul 3, 2023

I want to implement this!

At some point the spec changed to use FindViaPredicate ( O, len, direction, predicate, thisArg ) for Array.prototype.find, Array.prototype.findLast, %TypedArray%.prototype.findLast, et al. Do we want to refactor the existing implementations to use this?

If so, where would be a good place to add this? Under built-ins/array/mod.rs as a pub(crate) fn find_via_predicate? I don't have any experience with Rust modules yet, so a bit unsure what the way to go would be.

@HalidOdat
Copy link
Member

At some point the spec changed to use FindViaPredicate ( O, len, direction, predicate, thisArg ) for Array.prototype.find, Array.prototype.findLast, %TypedArray%.prototype.findLast, et al. Do we want to refactor the existing implementations to use this?

Yes, that would be optimal, This could be done In a separate PR.

If so, where would be a good place to add this? Under built-ins/array/mod.rs as a pub(crate) fn find_via_predicate? I don't have any experience with Rust modules yet, so a bit unsure what the way to go would be.

Yes, that's a good place :) , I usually put the helper fuctions based where it is defined in the spec then by frequency of use, since they are both used equally. array module is best.

@dirkdev98
Copy link
Contributor Author

Alright, will do the refactor first and implement the new functions afterwards. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants