Merge pull request #973 from jacereda/fix-suffix

Fix suffix docs and implementation, simplify prefix.
This commit is contained in:
Erik Svedäng 2020-11-17 23:59:46 +01:00 committed by GitHub
commit 2f302aa046
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -79,11 +79,11 @@
(doc prefix "Return the first `a` characters of the string `s`.")
(defn prefix [s a]
(from-chars &(Array.slice &(chars s) 0 a)))
(from-chars &(Array.prefix &(chars s) a)))
(doc suffix "Return the last `b` characters of the string `s`.")
(doc suffix "Returns the suffix string starting at the `b`th character.")
(defn suffix [s b]
(from-chars &(Array.slice &(chars s) b (length s))))
(from-chars &(Array.suffix &(chars s) b)))
(doc starts-with? "Check if the string `s` begins with the string `sub`.")
(defn starts-with? [s sub]

View File

@ -94,6 +94,10 @@
"dang"
&(suffix "svedang" 3)
"suffix works as expected")
(assert-equal test
"😲😲😲😲"
&(suffix "😲😲😲😲😲" 1)
"suffix works as expected II")
(assert-true test
(ends-with? "heller" "ler")
"ends-with? works as expected")