【心得】
有事情,候補XD
【今日湯底】
Definition
A Tidy number is a number whose digits are in non-decreasing order.
Task
Given a number, Find if it is Tidy or not .
(必須通過以下測試)
(ns kata.test
(:require [clojure.test :refer :all]
[kata :refer [tidy-number]]))
(deftest basic-tests
(is (= (tidy-number 12) true))
(is (= (tidy-number 102) false))
(is (= (tidy-number 9672) false))
(is (= (tidy-number 2789) true))
(is (= (tidy-number 2335) true)))
【我的答案】
(ns kata)
(defn tidy-number [n]
(= n (Integer/parseInt (clojure.string/join (map str (sort (str n))))))
)
思路:
sort
的參數必須給 string 先轉型別map
後會給成 ("1" "2")【其他人的答案】
(ns kata)
(defn tidy-number [n]
(apply <= (map #(Integer. (str %)) (str n))))
(ns kata)
(defn tidy-number [n]
(= (str n) (apply str (sort (str n)))))