-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71a51cf
commit b7df800
Showing
7 changed files
with
50 additions
and
71 deletions.
There are no files selected for viewing
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
module Anagram exposing (..) | ||
|
||
import List as List exposing (filter, sort) | ||
import String exposing (toList, toLower) | ||
import String exposing (toList, toLower) | ||
|
||
|
||
identifier_1 : String -> (List String -> List String) | ||
identifier_1 identifier_2 = | ||
List.filter (identifier_3 identifier_2) >> List.filter (identifier_4 identifier_2) | ||
|
||
|
||
identifier_3 : String -> (String -> Bool) | ||
identifier_3 identifier_2 identifier_5 = | ||
identifier_6 identifier_2 == identifier_6 identifier_5 | ||
|
||
|
||
identifier_4 : String -> (String -> Bool) | ||
identifier_4 identifier_7 identifier_8 = | ||
String.toLower identifier_7 /= String.toLower identifier_8 | ||
|
||
|
||
identifier_6 : String -> List Char | ||
identifier_6 = | ||
identifier_6 = | ||
String.toLower >> String.toList >> List.sort |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,41 @@ | ||
-- This is a demonstration solution that I use when mentoring, any | ||
-- This is a demonstration solution that I use when mentoring, any | ||
-- improvements / comments / suggestions welcome. | ||
|
||
-- I have changed the name of the exported function from `detect` to `filterAnagramsOf`, | ||
-- as I think it describes the intent better. Most times when you are using this module, | ||
-- as I think it describes the intent better. Most times when you are using this module, | ||
-- this name / function definition will tell you all you need to know, and you won't need | ||
-- to read anything else. | ||
|
||
-- If you want to know how the algorithm works (the stipulation that idenitcal words be | ||
-- removed is a debatable point for example) then you only have to read the body of | ||
-- removed is a debatable point for example) then you only have to read the body of | ||
-- `filterAnaagramsOf`. | ||
|
||
-- So to understand what this does and how it does it there are only 4 lines to read, | ||
-- So to understand what this does and how it does it there are only 4 lines to read, | ||
-- which I think is powerful. | ||
|
||
-- There is a solution available that uses more point free style | ||
|
||
|
||
module Anagram exposing (..) | ||
|
||
import List as List exposing (filter, sort) | ||
import String exposing (toList, toLower) | ||
|
||
|
||
filterAnagramsOf : String -> List String -> List String | ||
filterAnagramsOf word = | ||
List.filter (sortedLowercaseCharactersMatch word) | ||
>> List.filter (notExactlyTheSameWord word) | ||
>> List.filter (notExactlyTheSameWord word) | ||
|
||
|
||
sortedLowercaseCharactersMatch : String -> String -> Bool | ||
sortedLowercaseCharactersMatch word candidate = | ||
sortedLowercaseCharacters word == sortedLowercaseCharacters candidate | ||
|
||
notExactlyTheSameWord : String -> String -> Bool | ||
|
||
notExactlyTheSameWord : String -> String -> Bool | ||
notExactlyTheSameWord word1 word2 = | ||
String.toLower word1 /= String.toLower word2 | ||
|
||
|
||
sortedLowercaseCharacters : String -> List Char | ||
sortedLowercaseCharacters = | ||
String.toLower | ||
>> String.toList | ||
>> List.sort | ||
>> List.sort |