exercism

Exercism solutions.
Log | Files | Refs

commit bd7d8a2ccbd7a6c159c774d48b2054ae72284665
parent 7ab5ac1638bef763b8fa337c1db53fba933cd82e
Author: dwrz <dwrz@dwrz.net>
Date:   Tue,  5 Feb 2019 02:29:37 +0000

Refactor elisp/anagram/anagrams-for

Reformat.

Use push macro over low-level list-manipulation.

Diffstat:
Melisp/anagram/anagram.el | 14++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/elisp/anagram/anagram.el b/elisp/anagram/anagram.el @@ -29,18 +29,16 @@ CHAR-COUNT and COMPARISON-CHAR-COUNT should be alists in (character . count) for (setq are-equal nil)) (setq are-equal nil))))) -(defun anagrams-for(word anagrams) +(defun anagrams-for (word anagrams) "Return all elements of ANAGRAMS which are anagrams for WORD. Case insensitive." (let ((candidates ()) (word-char-count (get-char-count (downcase word)))) (dolist (candidate anagrams candidates) - (if (and - (not (string-equal word candidate)) - (equal (length word) (length candidate)) - (equal-char-count word-char-count (get-char-count (downcase candidate)))) - (if (> (length candidates) 0) - (add-to-list 'candidates candidate t) - (setq candidates (cons candidate nil))))))) + (when (and (not (string-equal word candidate)) + (= (length word) (length candidate)) + (equal-char-count word-char-count (get-char-count (downcase candidate)))) + (push candidate candidates))) + (reverse candidates))) ;;; anagram.el ends here