js-on-sx: Array.prototype find/findIndex/some/every honour thisArg + (v,i,arr)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
This commit is contained in:
@@ -2284,11 +2284,50 @@
|
||||
(>=
|
||||
(js-list-index-of arr (nth args 0) 0)
|
||||
0))))
|
||||
((= name "find") (fn (f) (js-list-find-loop f arr 0)))
|
||||
((= name "find")
|
||||
(fn (&rest args)
|
||||
(let
|
||||
((f (if (empty? args) :js-undefined (nth args 0)))
|
||||
(this-arg
|
||||
(cond
|
||||
((< (len args) 2) js-global-this)
|
||||
((js-undefined? (nth args 1)) js-global-this)
|
||||
((= (nth args 1) nil) js-global-this)
|
||||
(else (nth args 1)))))
|
||||
(js-list-find-loop f arr this-arg 0))))
|
||||
((= name "findIndex")
|
||||
(fn (f) (js-list-find-index-loop f arr 0)))
|
||||
((= name "some") (fn (f) (js-list-some-loop f arr 0)))
|
||||
((= name "every") (fn (f) (js-list-every-loop f arr 0)))
|
||||
(fn (&rest args)
|
||||
(let
|
||||
((f (if (empty? args) :js-undefined (nth args 0)))
|
||||
(this-arg
|
||||
(cond
|
||||
((< (len args) 2) js-global-this)
|
||||
((js-undefined? (nth args 1)) js-global-this)
|
||||
((= (nth args 1) nil) js-global-this)
|
||||
(else (nth args 1)))))
|
||||
(js-list-find-index-loop f arr this-arg 0))))
|
||||
((= name "some")
|
||||
(fn (&rest args)
|
||||
(let
|
||||
((f (if (empty? args) :js-undefined (nth args 0)))
|
||||
(this-arg
|
||||
(cond
|
||||
((< (len args) 2) js-global-this)
|
||||
((js-undefined? (nth args 1)) js-global-this)
|
||||
((= (nth args 1) nil) js-global-this)
|
||||
(else (nth args 1)))))
|
||||
(js-list-some-loop f arr this-arg 0))))
|
||||
((= name "every")
|
||||
(fn (&rest args)
|
||||
(let
|
||||
((f (if (empty? args) :js-undefined (nth args 0)))
|
||||
(this-arg
|
||||
(cond
|
||||
((< (len args) 2) js-global-this)
|
||||
((js-undefined? (nth args 1)) js-global-this)
|
||||
((= (nth args 1) nil) js-global-this)
|
||||
(else (nth args 1)))))
|
||||
(js-list-every-loop f arr this-arg 0))))
|
||||
((= name "reverse")
|
||||
(fn () (js-list-reverse-loop arr (- (len arr) 1) (list))))
|
||||
((= name "flat")
|
||||
@@ -2590,29 +2629,32 @@
|
||||
(define
|
||||
js-list-find-loop
|
||||
(fn
|
||||
(f arr i)
|
||||
(f arr this-arg i)
|
||||
(cond
|
||||
((>= i (len arr)) js-undefined)
|
||||
((js-to-boolean (f (nth arr i))) (nth arr i))
|
||||
(else (js-list-find-loop f arr (+ i 1))))))
|
||||
((js-to-boolean (js-call-with-this this-arg f (list (nth arr i) i arr)))
|
||||
(nth arr i))
|
||||
(else (js-list-find-loop f arr this-arg (+ i 1))))))
|
||||
|
||||
(define
|
||||
js-list-find-index-loop
|
||||
(fn
|
||||
(f arr i)
|
||||
(f arr this-arg i)
|
||||
(cond
|
||||
((>= i (len arr)) -1)
|
||||
((js-to-boolean (f (nth arr i))) i)
|
||||
(else (js-list-find-index-loop f arr (+ i 1))))))
|
||||
((js-to-boolean (js-call-with-this this-arg f (list (nth arr i) i arr)))
|
||||
i)
|
||||
(else (js-list-find-index-loop f arr this-arg (+ i 1))))))
|
||||
|
||||
(define
|
||||
js-list-some-loop
|
||||
(fn
|
||||
(f arr i)
|
||||
(f arr this-arg i)
|
||||
(cond
|
||||
((>= i (len arr)) false)
|
||||
((js-to-boolean (f (nth arr i))) true)
|
||||
(else (js-list-some-loop f arr (+ i 1))))))
|
||||
((js-to-boolean (js-call-with-this this-arg f (list (nth arr i) i arr)))
|
||||
true)
|
||||
(else (js-list-some-loop f arr this-arg (+ i 1))))))
|
||||
|
||||
(define
|
||||
js-list-flat-loop
|
||||
@@ -2688,11 +2730,12 @@
|
||||
(define
|
||||
js-list-every-loop
|
||||
(fn
|
||||
(f arr i)
|
||||
(f arr this-arg i)
|
||||
(cond
|
||||
((>= i (len arr)) true)
|
||||
((not (js-to-boolean (f (nth arr i)))) false)
|
||||
(else (js-list-every-loop f arr (+ i 1))))))
|
||||
((not (js-to-boolean (js-call-with-this this-arg f (list (nth arr i) i arr))))
|
||||
false)
|
||||
(else (js-list-every-loop f arr this-arg (+ i 1))))))
|
||||
|
||||
(define
|
||||
js-list-reverse-loop
|
||||
|
||||
Reference in New Issue
Block a user