Last active
February 9, 2026 02:02
-
-
Save vvgomes/b19a2f0134bbda9b79e1414889d4dec0 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
| node_modules/ | |
| package-lock.json |
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
| { | |
| "name": "palindrome", | |
| "version": "1.0.0", | |
| "description": "", | |
| "homepage": "https://gist.github.com/b19a2f0134bbda9b79e1414889d4dec0", | |
| "bugs": { | |
| "url": "https://gist.github.com/b19a2f0134bbda9b79e1414889d4dec0" | |
| }, | |
| "repository": { | |
| "type": "git", | |
| "url": "git+ssh://git@gist.github.com/b19a2f0134bbda9b79e1414889d4dec0.git" | |
| }, | |
| "license": "ISC", | |
| "author": "vvgomes", | |
| "type": "module", | |
| "main": "palindrome.js", | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "dependencies": { | |
| "ramda": "^0.32.0" | |
| } | |
| } |
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
| (ns palindrome | |
| (:require [clojure.test :refer [deftest is]])) | |
| (def drop-edges | |
| (comp drop-last rest)) | |
| (defn equal-edges? [w] | |
| (= (first w) (last w))) | |
| (def too-small? | |
| (comp (partial > 2) count)) | |
| (defn palindrome? [w] | |
| (or | |
| (too-small? w) | |
| (and | |
| (equal-edges? w) | |
| (palindrome? (drop-edges w))))) | |
| (deftest test-palindrome?->yes! | |
| (is (palindrome? "")) | |
| (is (palindrome? "a")) | |
| (is (palindrome? "aa")) | |
| (is (palindrome? "aba")) | |
| (is (palindrome? "abba")) | |
| (is (palindrome? "abcdedcba"))) | |
| (deftest test-palindrome?->no! | |
| (is (not (palindrome? "ab"))) | |
| (is (not (palindrome? "abb"))) | |
| (is (not (palindrome? "abaa"))) | |
| (is (not (palindrome? "abcdeecba")))) | |
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
| import { | |
| head, last, equals, and, equals, | |
| and, tail, gt, all, compose | |
| } from "ramda"; | |
| const dropEdges = | |
| compose(dropLast(1), tail); | |
| const equalEdges = (word) => | |
| equals(head(word), last(word)); | |
| const tooSmall = | |
| comp(gt(2), length); | |
| const isPalindrome = (word) => | |
| tooSmall(word) || and(equalEdges(word), isPalindrome(dropEdges(word))); | |
| all(equals(true), [ | |
| isPalindrome(""), | |
| isPalindrome("a"), | |
| isPalindrome("aa"), | |
| isPalindrome("aba"), | |
| isPalindrome("abba"), | |
| isPalindrome("abcdedcba") | |
| ]); | |
| all(equals(false), [ | |
| isPalindrome("ab"), | |
| isPalindrome("abb"), | |
| isPalindrome("abaa"), | |
| isPalindrome("abcdeecba") | |
| ]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment