Output numbers from 1 to x. If the number is divisible by 3, replace it with “Fizz”. If it is divisible by 5, replace it with “Buzz”. If it is divisible by 3 and 5 replace it with “FizzBuzz”.
(ns fizzbuzz.core)
(defn divisible-by? [divisor number]
(zero? (mod number divisor)))
(defn fizzbuzz [x]
(map #(cond
(divisible-by? 15 %) "FizzBuzz"
(divisible-by? 5 %) "Buzz"
(divisible-by? 3 %) "Fizz"
:else %)
(range 1 (inc x))))
(ns fizzbuzz.core-test
(:require [clojure.test :refer :all]
[fizzbuzz.core :refer :all]))
(deftest a-test1
(testing "Test 1"
(is (= (fizzbuzz 16) [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16]))))