Last active
December 23, 2025 03:47
-
-
Save sogaiu/59bd2522c38044da0ad9985d5cd22ab8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| (defn diff-path | |
| [left right] | |
| (var i 0) | |
| (var done false) | |
| (def [shorter longer] | |
| (if (<= (length left) (length right)) | |
| [left right] | |
| [right left])) | |
| (for j 0 (length shorter) | |
| (when (not= (get left j) (get right j)) | |
| (set done true) | |
| (set i j) | |
| (break))) | |
| (cond | |
| (not done) | |
| [shorter (string/slice longer (length shorter))] | |
| # | |
| (= 0 i) | |
| ["" nil] | |
| # | |
| [(string/slice shorter 0 i) ""])) | |
| (comment | |
| (diff-path "/usr/include" | |
| "/usr/include/fstab.h") | |
| # => | |
| ["/usr/include" "/fstab.h"] | |
| (diff-path "/tmp" "hello") | |
| # => | |
| ["" nil] | |
| (diff-path "/etc/motd" "/etc/issue") | |
| # => | |
| ["/etc/" ""] | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment