Fix splitByAll side effect

This commit is contained in:
2023-03-20 21:04:27 -06:00
parent 99727e3701
commit 6ccaa78ca2
2 changed files with 17 additions and 15 deletions

View File

@@ -1,15 +1,17 @@
(doFor name [ (doFor _ (range 2)
"Finn" (doFor name [
"Miguel" "Finn"
"George" "Miguel"
"Ernest" "George"
"Crawford" "Ernest"
"Howard" "Crawford"
"Troy" "Howard"
"Tracy" "Troy"
"Valeria" "Tracy"
"Vanessa" "Valeria"
] "Vanessa"
(assert (Names.isName name))) ]
(assert (Names.isName name)))
(assertEquals 5 .length (Names.findNames "Vanessa, Finn, and Tracy--and George--go to Troy's...")) (assertEquals 5 .length (Names.findNames "Vanessa, Finn, and Tracy--and George--go to Troy's..."))
)

View File

@@ -27,7 +27,7 @@
]) ])
(function :Array<String> splitByAll [:String text :Array<String> delims] (function :Array<String> splitByAll [:String text :Array<String> delims]
(if delims (ifLet [delims (delims.copy)]
(let [next (delims.shift) (let [next (delims.shift)
tokens (text.split next)] tokens (text.split next)]
(flatten (for token tokens (splitByAll token (delims.copy))))) (flatten (for token tokens (splitByAll token (delims.copy)))))