core/Array.carp: remove-idx function

This commit is contained in:
Joel Kaasinen 2018-12-07 14:00:52 +02:00
parent 4ad728d1cd
commit 87193e215a
2 changed files with 14 additions and 2 deletions

View File

@ -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)))
)

View File

@ -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"))