LoginSignup
2
2

More than 5 years have passed since last update.

condpを利用したFizzBuzz

Posted at
(defn fizzbuzz [x]
  (condp #(= (mod %2 %1) 0) x
    15 "FizzBuzz"
    3 "Fizz"
    5 "Buzz"
    x))

condの各条件の中で使用する変数が共通の場合、condpが便利。
'%1'には引数x、'%2'には場合分けの15,3,5がそれぞれ対応する。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2