-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Let's say I have a vector of numbers [9,5,6,5], and I want to replace half of them with "xxx".
This is the correct solution:
(defn mask-digit [digits index]
(if (>= index 2) "xxx"
(str (get digits index))
))
(print (map (mask-digit [9,5,6,5]) [0 1 2 3])) ; > [9,5,xxx,xxx]
If I remove the str, I get an error (which I expected because I want to mix strings and numbers in the same vector):
(defn mask-digit [digits index]
(if (>= index 2) "xxx"
(get digits index)
))
(print (map (mask-digit [9,5,6,5]) [0 1 2 3])) ; > Type Error! Expected 'Number', but got 'String'
The funny thing is that if I list the vector of indexes in the second argument in reverse order, the error disappears and the script fails silently:
(defn mask-digit [digits index]
(if (>= index 2) "xxx"
(get digits index)
))
(print (map (mask-digit [9,5,6,5]) [3 2 1 0])) ; > [No output]
Metadata
Metadata
Assignees
Labels
No labels