Skip to content

Implement array.fill#1497

Merged
Perryvw merged 1 commit intomasterfrom
array-fill
Oct 3, 2023
Merged

Implement array.fill#1497
Perryvw merged 1 commit intomasterfrom
array-fill

Conversation

@Perryvw
Copy link
Member

@Perryvw Perryvw commented Oct 2, 2023

Implements Array.prototype.fill.

This implementation slightly differs from the ECMAScript specification in that it will extend the array until the given length (if given), rather than only filling until the original length and stopping, as is specified by the ECMAScript specification.

This alternate behavior is justified by the fact that there is not really any other convenient way of initializing an array of specific length. (new Array() constructor doesn't work, Lua arrays are just hash tables anyway). So with this slight modification you can initialize an array of given length as [].fill(defaultValue, 0, desiredLength) (might need some casting if you use an empty literal).

@Perryvw Perryvw merged commit 45f6078 into master Oct 3, 2023
@Perryvw Perryvw deleted the array-fill branch October 3, 2023 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant