Created
September 12, 2023 17:39
-
-
Save chase-lambert/f407588190788568e97c42b478ef9fcb to your computer and use it in GitHub Desktop.
rendezvous with cassidoo challenge: 23-09-11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns separate-and-sort | |
(:require [clojure.test :refer [deftest is]])) | |
(defn separate-and-sort [nums] | |
(let [nums (sort (remove zero? nums))] | |
(reduce (fn [[evens odds] n] | |
(if (even? n) | |
[(conj evens n) odds] | |
[evens (conj odds n)])) | |
[[] []] | |
nums))) | |
(deftest separate-and-sort-test | |
(is (= [[2 4 8] [1 3 5 7 9]] | |
(separate-and-sort [4 3 2 1 5 7 8 9]))) | |
(is (= [[] [1 1 1 1]] | |
(separate-and-sort [1 1 1 1])))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment