summaryrefslogtreecommitdiff
path: root/coinlist.hs
blob: 76007fd83e6216fec573974a06788842adfafa10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-- I don't remember what the problem was... I think I had to index the LinkedIn
-- directory using a tree?
--
-- https://www.linkedin.com/directory/people-v/

data User = User
  { id :: Int
  , name :: String
  }

data Tree
  = Node
  | Tree

data Node
  = Start User
  | End User

(Node (Start (id "V American Clifton"))
      (End (id "v♡ g♡"))

(Tree
(Node (Start (id "V American Clifton"))
      (End (id "VANESSA MITCHELL")))
(Node (Start (id "Vahid Sab"))
      (End (id "Val Hoskins")))
)


(Node V)




1. First exact matches
2. Results where one of the words is an exact match
3. Results that start with the search string
4. The rest, alphabetically sorted


query: "word"
correct ordering: [“Word”, “Microsoft Word”, “Wordpress”, “1Password”, “Google AdWords”]

"word", "Microsoft Word"

for w in words:
    if exactMatch(w, query):
        putInFront(w, words)
    else if contains(w, query):
        putBehindExactMatches(w, query, words)
    else if: startsWith(w, query):
        putBehindContains(w, query, words)
    else
        sortAlphabetically(words)



f :: String -> [String] -> [String]
f "" ls = ls
f _ [] = []
f q (x:xs) =
    if q == x then x:(f xs)
    else if q `isPrefixOf` x then (f xs):x
    else if q `isInfixOf` x then placeAfterMatches q (x:xs)
    else alphabatize((f xs):x)


placeAfterMatches :: String -> [String] -> [String]
placeAfterMatches _ [] = []
placeAfterMatches q (x:xs) = if q == x then x:(placeAfterMatches q xs) else x:xs

placeAfterContains :: String -> [String] - [String]
placeAfterContains q (x:xs) = if q `isInfixOf` x then x:(placeAfterContains q xs) else x:xs