mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
core/Array.carp: remove-idx function
This commit is contained in:
parent
4ad728d1cd
commit
87193e215a
@ -246,4 +246,12 @@
|
||||
(filter &(fn [x] (not (= el x)))
|
||||
arr))
|
||||
|
||||
)
|
||||
(doc remove-idx "Remove element at index idx from arr")
|
||||
(defn remove-idx [i arr]
|
||||
(do
|
||||
;;(assert (<= 0 i))
|
||||
;;(assert (< i (Array.length &arr)))
|
||||
(for [j i (Int.dec (Array.length &arr))]
|
||||
(aset! &arr j @(nth &arr (inc j))))
|
||||
(pop-back arr)))
|
||||
)
|
||||
|
@ -233,4 +233,8 @@
|
||||
(assert-equal test
|
||||
&[1 3]
|
||||
&(remove &2 [1 3])
|
||||
"remove works when element is not found"))
|
||||
"remove works when element is not found")
|
||||
(assert-equal test
|
||||
&[1 3]
|
||||
&(remove-idx 1 [1 2 3])
|
||||
"remove-idx works"))
|
||||
|
Loading…
Reference in New Issue
Block a user