Take your name and the name of another student in the group and create a combined name
A collection of two people
Create a collection containing your full name and the name of another person (or two imaginary people if you prefer)
Give your collection a name so you can use it in later exercises on this page.
Split first and last names
Assuming there is a first and last name for each person we need to split them into individual strings first.
Write a function call to split each name in your
(clojure.string/split students #" ") ;; ;; => ["Ada" "Lovelace" "Anne-Marie" "Imafidon"]
Mapping over the student collection gives cleaner return value
(map #(clojure.string/split % #" ") students)
We can also flatten the result to make it look nicer
(flatten (map #(clojure.string/split % #" ") students))
clojure.string/split function will split a string on a given pattern (regular expression), such as a space:
Name splitting function
Write a function called
name-split that a full name as a string and return two seperate strings, one for the first name and one for the last name.
Jumble the names
Write a function to jumble up the first and last names to create a new person
For example, take the first name from the first person and join it with the last name from the second person
(defn jumble-names [names] (let [first-person (first names) second-person (second names) first-person-first-name (first (name-split first-person)) second-person-second-name (second (name-split second-person))] (str "Hello " first-person-first-name second-person-second-name))) ;; (jumble-names students) ;; => "Hello AdaImafidon"
let function defines local names that you can use for temporary values.
Using several names with the
let function can make this challenge a little simpler to solve