-
-
Save sgrove/a38106fe15a521288708 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Clojurescript, detect if a string contains a double-byte char. As soon as we find one, we should immediately return true | |
(defn double-byte-str? [string] | |
(.log js/console (str "Checking: " string)) | |
(cond (empty? string) nil | |
(> (.charCodeAt string 0) 255) true | |
:else (recur (rest string)))) | |
; Javascript version of the function | |
String.prototype.isDoubleByte = function() { | |
for (var i = 0, n = this.length; i < n; i++) { | |
if (this.charCodeAt( i ) > 255) { return true; } | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment