stdlib-js / stdlib-js/stdlib

RFC: add functional equivalent of `Array.prototype.copyWithin`

Đang mở
#203 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
difficulty: 3 Feature Help Wanted RFC Utilities
Ngôn ngữ chính
JavaScript
Star
6k
Fork
1.3k
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
611

Mô tả

## Checklist

> Please ensure the following tasks are completed before submitting a feature request.

- [x] Read and understood the [Code of Conduct][code-of-conduct].
- [x] Searched for existing issues and pull requests.
- [x] The issue name begins with `RFC:`.

## Description

> Description of the feature request.

This RFC proposes to add a "functional" equivalent of [`Array.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin) and [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin).

Package: `@stdlib/utils/copy-within`
Alias: `copyWithin`

The interface would be as follows:

```javascript
/**
* @param {Collection} collection - input collection
* @param {integer} target - target index
* @param {integer} [start=0] - source start index
* @param {integer} [end=collection.length] - source end index
* @returns {Collection} modified input collection
*/
function copyWithin( collection, target ) {
if ( !isCollection( collection ) ) {
throw new TypeError( '...' );
}
// implementation...
}
```
If a provided `collection` has a built-in `copyWithin` method, the implementation would defer to that method. Otherwise, the implementation would provide a "polyfill", thus extending `copyWithin` support to environments lacking the built-in API for `Array` and `TypedArray`.

## Related Issues

> Does this feature request have any related issues?

No.

## Questions

> Any questions for reviewers?

No.

## Other

> Any other information relevant to this feature request? This may include screenshots, references, sample output, and/or implementation notes.

No.

[code-of-conduct]: https://github.com/stdlib-js/stdlib/blob/develop/CODE_OF_CONDUCT.md

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.