-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.js
85 lines (71 loc) · 2.52 KB
/
examples.js
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
74
75
76
77
78
79
80
81
82
83
84
85
// 1. Fuzzy search in an array of strings
console.log('\n*** Fuzzy search in an array of strings ***');
const SearchEngine = require('./search-engine');
let searchEngine = new SearchEngine();
// Define the names array
let names = [
"Tiffany Ellis", "Jon Mcdaniel", "Marcella Bailey",
"Earnest Hicks", "Christian Mclaughlin", "Martin Baker",
"Jodi Hogan", "Willie Estrada", "Joe King",
"Irene Hall", "Leo Wilkerson", "Dominick Weber",
"Elena Perry", "Kristy Gibson", "James Cunningham",
"Tina Ross", "Beulah Mccarthy", "Carlos Wallace",
"Doris Barker", "Josephine Gibbs", "Erik Wells",
"Elsie Erickson", "Jerald Adkins", "Alfred Huff",
"Blanche Holt", "Elvira Wright", "Kenneth Fitzgerald",
"Joan Robinson", "Melissa Tucker", "Evelyn Clark",
"Gerald Perkins", "Johnny Burton", "Hector Herrera",
"Gayle Williams", "Bernice Harrington", "Timmy Brady",
"Jennie Moss", "May Greer", "Thelma Lloyd",
"Ida Craig", "June Hughes", "Beverly Graves",
"Alfonso Ramos", "Cecilia Colon", "Ed Barnes",
"Ken Zimmerman", "Nora Hunter", "Seth Harris",
"Kristina Rivera", "Archie Brown"
];
// Set count of required results (3 by default)
searchEngine.setStackMaxLength(5);
// Searching of names similar to "Jonh Baker" in the names array
console.log(
searchEngine.search("John Baker", names)
);
// 2. Fuzzy search in an array of objects with nested strings
console.log('\n*** Fuzzy search in an array of objects with nested strings ***');
let nestedNames = [
{name: "Tiffany Ellis"},
{name: "Jon Mcdaniel"},
{name: "Marcella Bailey"},
{name: "Earnest Hicks"},
{name: "Christian Mclaughlin"},
{name: "Martin Baker"},
{name: "Jodi Hogan"},
{name: "Willie Estrada"},
{name: "Joe King"},
{name: "Irene Hall"}
];
// Set count of required results (3 by default)
searchEngine.setStackMaxLength(1);
// Searching of names similar to "Jonh Baker" in the names array (callback
// extracts name from an object)
console.log(
searchEngine.search("Martin Bailey", nestedNames, (item) => {
return item.name;
})
);
// 3. Fuzzy comparing of strings
console.log('\n*** Fuzzy comparing of strings ***');
const StringsComparator = require('./strings-comparator');
let stringsComparator = new StringsComparator();
// full view
console.log(
stringsComparator.compare('contact', 'contract')
);
console.log(
stringsComparator.compare('modification', 'modernization')
);
// simplified view
console.log(
stringsComparator.compare('contact', 'contract', true)
);
console.log(
stringsComparator.compare('modification', 'modernization', true)
);