diff options
author | Juan Carlos <juancarlospaco@gmail.com> | 2022-05-24 12:37:19 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-24 17:37:19 +0200 |
commit | b1b5e3ab10749851e942d624ee85188d8b06822e (patch) | |
tree | 1723f4298972f40b65d0f13d162b11f6ca427b77 | |
parent | 05c0419658e3f97c29a12a16e99c0f8b842622c8 (diff) | |
download | Nim-b1b5e3ab10749851e942d624ee85188d8b06822e.tar.gz |
Add Array.shift (#19811)
* Add Array.shift for JavaScript targets * Add Array.shift for JavaScript targets
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | lib/js/jscore.nim | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md index 3b2685547..e120dcfb8 100644 --- a/changelog.md +++ b/changelog.md @@ -37,7 +37,7 @@ becomes an alias for `addr`. - Added `initDateTime` in `times` to create a datetime from a weekday, and ISO 8601 week number and week-based year. - Added `getIsoWeekAndYear` in `times` to get an ISO week number along with the corresponding ISO week-based year from a datetime. - Added `getIsoWeeksInYear` in `times` to return the number of weeks in an ISO week-based year. - +- Added [`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift) for JavaScript targets. - Added `std/oserrors` for OS error reporting. Added `std/envvars` for environment variables handling. - Removed deprecated `oids.oidToString`. - Remove define `nimExperimentalAsyncjsThen` for `std/asyncjs.then` and `std/jsfetch`. diff --git a/lib/js/jscore.nim b/lib/js/jscore.nim index 61c188431..4518f32ce 100644 --- a/lib/js/jscore.nim +++ b/lib/js/jscore.nim @@ -123,3 +123,12 @@ since (1, 5): assert [1, 2, 3, 4, 5].copyWithin(0, 3) == @[4, 5, 3, 4, 5] assert [1, 2, 3, 4, 5].copyWithin(0, 3, 4) == @[4, 2, 3, 4, 5] assert [1, 2, 3, 4, 5].copyWithin(-2, -3, -1) == @[1, 2, 3, 3, 4] + + +since (1, 7): + func shift*[T](self: seq[T]): T {.importjs: "#.$1()".} = + ## https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift + runnableExamples: + var arrai = @[1, 2, 3] + assert arrai.shift() == 1 + assert arrai == @[2, 3] |