iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 25
0
自我挑戰組

各種筆記系列 第 25

[Kata] Clojure - Day 25

Find the odd int

Given an array of integers, find the one that appears an odd number of times.
There will always be only one integer that appears an odd number of times.

找出陣列中出現基數次數的數字

Solution

(ns find-the-odd-int)

(defn find-odd [xs]
  (first (keys (filter (comp odd? second) (frequencies xs)))))
(first coll)
;; Returns the first item in the collection.

(first [1 2])  ; 1

(second x) (fnext x)
;; Same as (first (next x))

(second [1 2]) ; 2

(next coll)
;; Returns a seq of the items after the first.

(next [1 2])  ; 2
(comp)(comp f)(comp f g)(comp f g & fs)

(filter (comp not zero?) [0 1 0 2 0 3 0])  ;; (1 2 3)

上一篇
[Kata] Clojure - Day 24
下一篇
[Kata] Clojure - Day 26
系列文
各種筆記30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言