Skip to content

Instantly share code, notes, and snippets.

@chase-lambert
Created September 12, 2023 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chase-lambert/f407588190788568e97c42b478ef9fcb to your computer and use it in GitHub Desktop.
Save chase-lambert/f407588190788568e97c42b478ef9fcb to your computer and use it in GitHub Desktop.
rendezvous with cassidoo challenge: 23-09-11
(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