Clojure Study Tool

Learn Clojure through practical code challenges - based on Brave Clojure
✓ Solved: 0 ✗ Given up: 0 Total: 18

Syntax

if, do, and when

BEGINNER Control Flow

This code should print 'Success!' and then return 'By Zeus!' but it doesn't work. Fix the if expression so it prints the message AND returns the string.

Truthiness and nil

BEGINNER Control Flow

This function checks if a value is 'safe' to use (truthy). Someone from JavaScript wrote it and added extra checks that are wrong in Clojure. Fix the function so the output is exactly: true false true false true

Data Structures

Map Lookups

BEGINNER Maps

This code should print 'Charlie McFishwich' but it gives an error. Fix the map access to get the correct values.

Vectors vs Lists

BEGINNER Collections

This code should print '[1 2 3 4]' but it prints something else. Fix the code so the element is added to the END of the collection.

Sets and Uniqueness

BEGINNER Sets

This code should print '3' (the count of unique values) but it prints the wrong number. Fix it using a set.

Functions

Defining Functions

BEGINNER defn

Define a function called 'greet' that takes a name and returns 'Hello, <name>!'. The code should print 'Hello, Clojure!'.

Anonymous Functions

INTERMEDIATE Anonymous Functions

Use map with an anonymous function to triple each number. The code should print '(3 6 9 12)'.

Destructuring Magic

INTERMEDIATE Destructuring

This function should print the first and second items from the vector. Fix the parameter destructuring so the output is: First: oven Second: bike

Functions Returning Functions

INTERMEDIATE Closures

Create a function called 'dec-maker' that takes a number and returns a new function that subtracts that number. The code should print '1'.

Putting It Together

let Bindings

BEGINNER let

Use let to bind 'first-name' and 'last-name' from the vector, then print the full name. Output should be 'Pongo Dalmatian'.

loop and recur

INTERMEDIATE Recursion

This loop should count from 0 to 4 and then print 'Done!'. Fix the loop so the output is: 0 1 2 3 4 Done!

The Power of reduce

INTERMEDIATE reduce

Use reduce to implement a function 'mapset' that works like map but returns a set. The code should print '#{2 3 4}'.

Core Functions

map doesn't keep your vector

BEGINNER map / lazy seqs

We pass a vector to map and expect a vector back. The current code prints (2 3 4) — a list. Make it print the vector [2 3 4].

conj swallowed my vector

BEGINNER conj / into

We want to extend [1 2 3] with the elements of [4 5 6], printing [1 2 3 4 5 6]. The current code prints [1 2 3 [4 5 6]] — the second vector got nested instead.

Where did my max go?

BEGINNER apply

We have a vector of numbers and want to print the largest one. The current code just prints the whole vector back. Make it print 9.

Subtract Ten From

INTERMEDIATE partial

We're trying to define 'subtract 10 from a number': calling (sub10 3) should print -7. The current definition prints 7 instead. Replace the definition.

take-while bails too early

INTERMEDIATE take-while vs filter

We want every even number from the sequence, printing (2 4 6 8 10). The current code prints only (2 4 6) — it stops at the first odd number and ignores the rest.

A map of pairs is not a map

INTERMEDIATE seq on map / into {}

We want to double every value in the map, printing {:a 2, :b 4, :c 6}. The current code prints a sequence of pairs ([:a 2] [:b 4] [:c 6]) instead. Restore the map shape.