Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Array.prototype.transfer = function transfer(target=0,start=0, end=this.length, fill=missingMarker) {
/*
The sequence of array elements of array from start up to but not including end are transferred within
the array to the span starting at the index target. The length of the array is not modified.
start and end are interpretation the same as for slice,
negative start, end, and target indices are converted to positive indices relative to the lenth of the array.
If end<=start no elements are transfered.
If end>this.length or target+(end-start)>this.length a range error is thrown and no elements are modified.
Array elements are sequntially in a manner appropiate to avoid overlap conflicts. target<=start a left to right
transfer is performed. If target>start a right to left transfer is performed.
If a target element is encountered that cannot be assigned, a type error is thrown and no additional elements are modified.
Missing elements are processed as if they had the value undefined. "holes" are not transfered.
The fill argument is optional, if it is present then any array elements in the span start..stop that are not also in
the target span are set to the fill value. If fill is not present such elements are not modified.
*/
//algorithm to come
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.