Skip to content

Commit fee87e0

Browse files
author
Ivan Shamshurin
committed
working palindrome
added recur palindrome function
1 parent ad98336 commit fee87e0

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
(ns otus-02.homework.palindrome
22
(:require [clojure.string :as string]))
33

4+
(defn transform-string [s]
5+
(-> s
6+
(string/replace #"[,.-:;!?\"' ]" "")
7+
(string/lower-case)))
48

5-
(defn is-palindrome [test-string])
9+
(defn recur-palindrom [test-vec]
10+
(let [go-next (= (get test-vec 0) (get test-vec (dec (count test-vec))))]
11+
(cond
12+
(empty? test-vec) true
13+
(== (count test-vec) 1) true
14+
(not go-next) false
15+
:else (recur-palindrom (subvec test-vec 1 (dec (count test-vec)))))))
616

17+
(defn is-palindrome [test-string]
18+
(let [s (transform-string test-string)
19+
s-vec (vec s)]
20+
(recur-palindrom s-vec)))
21+
22+
(comment
23+
(is-palindrome "Civ, ic!"))

0 commit comments

Comments
 (0)