Created
December 19, 2013 05:00
-
-
Save anonymous/8034650 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
(use 'clojure.string) | |
(defn first-parts-are? [s test-string] | |
(let [cleaned-string (subs s 0 (min | |
(count test-string) | |
(count s)))] | |
(= test-string cleaned-string))) | |
(defn is-a-comment [line] | |
(some true? (map | |
(partial first-parts-are? line) | |
["*" "/**" "//"]))) | |
(defn count-code-lines [s] | |
(let [ready-lines (map trim (split-lines our-string)) | |
total (count splitted) | |
commented-lines (count | |
(filter is-a-comment splitted))] | |
(- total commented-lines))) | |
(def our-string " // This file contains 3 lines of code | |
public interface Dave { | |
/** | |
* count the number of lines in a file | |
*/ | |
int countLines(File inFile); // not the real signature! | |
}" ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment