|
1 | | -function flattenDeep (arr) { |
2 | | - return Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)) , []) : [arr]; |
3 | | -} |
4 | | - |
5 | | -function areArgsValid (mainString, targetStrings) { |
6 | | - if (typeof mainString !== 'string') return false; |
7 | | - if (!Array.isArray(targetStrings)) return false; |
8 | | - if (!targetStrings.length) return false; |
9 | | - if (targetStrings.find(s => typeof s !== 'string')) return false; |
10 | | - return true; |
11 | | -} |
12 | | - |
13 | | -function letterPairs (str) { |
14 | | - const pairs = []; |
15 | | - for (let i = 0, max = str.length - 1; i < max; i++) pairs[i] = str.substring(i, i + 2); |
16 | | - return pairs; |
17 | | -} |
18 | | - |
19 | | -function wordLetterPairs (str) { |
20 | | - const pairs = str.toUpperCase().split(' ').map(letterPairs); |
21 | | - return flattenDeep(pairs); |
22 | | -} |
| 1 | +module.exports = { |
| 2 | + compareTwoStrings, |
| 3 | + findBestMatch |
| 4 | +}; |
23 | 5 |
|
24 | 6 | function compareTwoStrings (str1, str2) { |
25 | 7 | if (!str1.length && !str2.length) return 1; // if both are empty strings |
@@ -49,8 +31,25 @@ function findBestMatch (mainString, targetStrings) { |
49 | 31 | return { ratings, bestMatch }; |
50 | 32 | } |
51 | 33 |
|
| 34 | +function flattenDeep (arr) { |
| 35 | + return Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)) , []) : [arr]; |
| 36 | +} |
52 | 37 |
|
53 | | -module.exports = { |
54 | | - compareTwoStrings, |
55 | | - findBestMatch |
56 | | -}; |
| 38 | +function areArgsValid (mainString, targetStrings) { |
| 39 | + if (typeof mainString !== 'string') return false; |
| 40 | + if (!Array.isArray(targetStrings)) return false; |
| 41 | + if (!targetStrings.length) return false; |
| 42 | + if (targetStrings.find(s => typeof s !== 'string')) return false; |
| 43 | + return true; |
| 44 | +} |
| 45 | + |
| 46 | +function letterPairs (str) { |
| 47 | + const pairs = []; |
| 48 | + for (let i = 0, max = str.length - 1; i < max; i++) pairs[i] = str.substring(i, i + 2); |
| 49 | + return pairs; |
| 50 | +} |
| 51 | + |
| 52 | +function wordLetterPairs (str) { |
| 53 | + const pairs = str.toUpperCase().split(' ').map(letterPairs); |
| 54 | + return flattenDeep(pairs); |
| 55 | +} |
0 commit comments