Clojure Tidbits - Consecutive elements in a sequence?

20 Aug 2014

I have recently come across an interesting question that need to be solved using functional programming techniques. So I thought, I shall give it a shot in clojure.

Question

How do you determine if all the elements in a given sequence are all consecutive elements?

General Idea

  1. Sort the sequence
  2. Compare each element with the next element & it should differ by 1.

Exact clojure