Skip to content

Commit

Permalink
reverse, fixes #61
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Aug 29, 2022
1 parent 0c39752 commit dadd31d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,3 +935,10 @@ export function keep(pred, coll) {
}
});
}

export function reverse(coll) {
if (coll instanceof Array) {
// performance: we don't need to copy to another array first
return coll.reverse();
} else return [...coll].reverse();
}
1 change: 1 addition & 0 deletions resources/clava/core.edn
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
repeat
reset_BANG_
rest
reverse
satisfies_QMARK_
second
select_keys
Expand Down
4 changes: 4 additions & 0 deletions test/clava/compiler_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,5 +1094,9 @@
(is (eq (keep #(when (odd? %) (inc %)) [1 2 3])
(vec (jsv! '(keep #(when (odd? %) (inc %)) [1 2 3]))))))

(deftest reverse-test
(is (eq (reverse [1 2 3]) (jsv! '(reverse [1 2 3]))))
(is (eq (reverse (range 10)) (jsv! '(reverse (range 10))))))

(defn init []
(cljs.test/run-tests 'clava.compiler-test 'clava.jsx-test))

0 comments on commit dadd31d

Please sign in to comment.