-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorting.clj
More file actions
23 lines (18 loc) · 755 Bytes
/
sorting.clj
File metadata and controls
23 lines (18 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(ns clojurelogic.sorting)
(defn remove-first-occurence [item items]
(let [matched-items (filter #(= % item) items)
new-items-after-remove (remove #(= % item) items)
final-items (if (> (count matched-items) 1)
(conj (vec new-items-after-remove) (last matched-items))
new-items-after-remove)]
final-items))
(defn sortFun
([unSortedItems]
(sortFun unSortedItems [] ))
([unSortedItems sortedItems ]
(if (empty? unSortedItems)
sortedItems
(let [smallest (apply min unSortedItems)
new-sorted-items (conj sortedItems smallest)
new-unsorted-list (remove-first-occurence smallest unSortedItems)]
(recur new-unsorted-list new-sorted-items)))))