Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns paging-task.ad-hoc)
- ;;; idea:
- ;;; drop fixed number of points (1,2,3, current-1,current,current+1,last-2,last-1,last)
- ;;; sort
- ;;; remove duplicated
- ;;; insert separator
- (defn- insert-separator [separator coll]
- (loop [result []
- c coll]
- (if (empty? c)
- result
- (if (empty? (rest c))
- (conj result (first c))
- (if (= (inc (first c)) (second c))
- (recur (conj result (first c)) (rest c))
- (recur (conj (conj result (first c)) separator) (rest c)))))))
- (defn get-pages [total current]
- (let [intervals [[1 (min total 3)]
- [(max 1 (dec current)) (min total (inc current))]
- [(max 1 (- total 2)) total]]
- points (mapcat (fn [[a b]] (range a (inc b))) intervals)]
- (->> points
- (sort)
- (distinct)
- (insert-separator "...")
- (map str))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement