This commit is contained in:
Rohit Tanwar
2018-02-18 20:05:13 +05:30
parent 685a64adde
commit 9bc5bd67c5
8 changed files with 145 additions and 163 deletions

View File

@ -1,33 +0,0 @@
### fuzzySearch
Determines if the `patrn` matches with `str`
Loops through `str` and determines if it contains all characters of `patrn` and in the correct order. Both the strings are converted to lower case.
Taken from [here](https://github.com/forrestthewoods/lib_fts/blob/80f3f8c52db53428247e741b9efe2cde9667050c/code/fts_fuzzy_match.js#L18).
``` js
fuzzySearch = (patrn, str) => {
const pattern = patrn;
const string = str;
let patternIdx = 0;
let strIdx = 0;
let patternLength = pattern.length;
let strLength = string.length;
while (patternIdx !== patternLength && strIdx !== strLength) {
let patternChar = pattern[patternIdx].toLowerCase();
let strChar = string[strIdx].toLowerCase();
if (patternChar === strChar)
++patternIdx;
++strIdx;
}
return patternLength !== 0 && strLength !== 0 && patternIdx === patternLength ? true : false;
}
```
``` js
fuzzySearch('rt','Rohit'); // true
fuzzySearch('tr','Rohit'); // false
```

View File

@ -20,8 +20,8 @@ const levenshteinDistance = (string1,string2) => {
}
}
}
return matrix[string2.length][string1.length]
}
return matrix[string2.length][string1.length];
};
```
```js

View File

@ -82,7 +82,6 @@ forOwnRight:object
fromCamelCase:string
functionName:function,utility
functions:object,function
fuzzySearch:string,utility
gcd:math,recursion
geometricProgression:math
get:object
@ -145,6 +144,7 @@ join:array
JSONToFile:node,json
last:array
lcm:math,recursion
levenshteinDistance:string,utility
longestItem:array,string,utility
lowercaseKeys:object
luhnCheck:math,utility
@ -284,4 +284,4 @@ xProd:array,math
yesNo:utility,regexp
zip:array
zipObject:array,object
zipWith:uncategorized
zipWith:array,function,advanced

View File

@ -1,19 +0,0 @@
fuzzySearch = (patrn, str) => {
const pattern = patrn;
const string = str;
let patternIdx = 0;
let strIdx = 0;
let patternLength = pattern.length;
let strLength = string.length;
while (patternIdx !== patternLength && strIdx !== strLength) {
let patternChar = pattern[patternIdx].toLowerCase();
let strChar = string[strIdx].toLowerCase();
if (patternChar === strChar)
++patternIdx;
++strIdx;
}
return patternLength !== 0 && strLength !== 0 && patternIdx === patternLength ? true : false;
}
module.exports = fuzzySearch;

View File

@ -1,15 +0,0 @@
const test = require('tape');
const fuzzySearch = require('./fuzzySearch.js');
test('Testing fuzzySearch', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof fuzzySearch === 'function', 'fuzzySearch is a Function');
t.true(fuzzySearch('rt','Rohit'),'Provided examples work');
t.false(fuzzySearch('tr','Rohit'),'Provided examples work');
//t.deepEqual(fuzzySearch(args..), 'Expected');
//t.equal(fuzzySearch(args..), 'Expected');
//t.false(fuzzySearch(args..), 'Expected');
//t.throws(fuzzySearch(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,18 @@
const levenshteinDistance = (string1,string2) => {
if(string1.length === 0) return string2.length;
if(string2.length === 0) return string1.length;
let matrix = Array(string2.length+ 1).fill(0).map((x,i) => [i]);
matrix[0] = Array(string1.length + 1).fill(0).map((x,i) => i);
for(i = 1;i <= string2.length;i++){
for(j = 1;j<=string1.length; j++){
if(string2[i-1] === string1[j-1]){
matrix[i][j] = matrix[i-1][j-1];
}
else{
matrix[i][j] = Math.min(matrix[i-1][j-1]+1,matrix[i][j-1]+1,matrix[i-1][j]+1);
}
}
}
return matrix[string2.length][string1.length];
};
module.exports = levenshteinDistance;

View File

@ -0,0 +1,13 @@
const test = require('tape');
const levenshteinDistance = require('./levenshteinDistance.js');
test('Testing levenshteinDistance', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof levenshteinDistance === 'function', 'levenshteinDistance is a Function');
//t.deepEqual(levenshteinDistance(args..), 'Expected');
//t.equal(levenshteinDistance(args..), 'Expected');
//t.false(levenshteinDistance(args..), 'Expected');
//t.throws(levenshteinDistance(args..), 'Expected');
t.end();
});

View File

@ -1,20 +1,20 @@
Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Test log for: Sun Feb 18 2018 19:56:04 GMT+0530 (India Standard Time)
> 30-seconds-of-code@0.0.2 test /home/travis/build/Chalarangelo/30-seconds-of-code
> 30-seconds-of-code@0.0.2 test R:\github\30-seconds-of-code
> tape test/**/*.test.js | tap-spec
Testing all
all is a Function
Returns true for arrays with no falsey values
Returns false for arrays with 0
Returns false for arrays with NaN
Returns false for arrays with undefined
Returns false for arrays with null
Returns false for arrays with empty strings
Returns true with predicate function
Returns false with a predicate function
all is a Function
Returns true for arrays with no falsey values
Returns false for arrays with 0
Returns false for arrays with NaN
Returns false for arrays with undefined
Returns false for arrays with null
Returns false for arrays with empty strings
Returns true with predicate function
Returns false with a predicate function
Testing anagrams
@ -25,12 +25,12 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing any
any is a Function
Returns true for arrays with at least one truthy value
Returns false for arrays with no truthy values
Returns false for arrays with no truthy values
Returns true with predicate function
Returns false with a predicate function
any is a Function
Returns true for arrays with at least one truthy value
Returns false for arrays with no truthy values
Returns false for arrays with no truthy values
Returns true with predicate function
Returns false with a predicate function
Testing approximatelyEqual
@ -42,8 +42,8 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing arrayToHtmlList
arrayToHtmlList is a Function
Tested by @chalarangelo on 16/02/2018
arrayToHtmlList is a Function
Tested by @chalarangelo on 16/02/2018
Testing ary
@ -64,18 +64,18 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing average
average is a Function
average(true) returns 0
average(false) returns 1
average(9, 1) returns 5
average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631) returns 32163.909090909092
average(1, 2, 3) returns 2
average(null) returns 0
average(1, 2, 3) returns NaN
average(String) returns NaN
average({ a: 123}) returns NaN
average([undefined, 0, string]) returns NaN
average([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run
average is a Function
average(true) returns 0
average(false) returns 1
average(9, 1) returns 5
average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631) returns 32163.909090909092
average(1, 2, 3) returns 2
average(null) returns 0
average(1, 2, 3) returns NaN
average(String) returns NaN
average({ a: 123}) returns NaN
average([undefined, 0, string]) returns NaN
average([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run
Testing averageBy
@ -173,8 +173,8 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing chainAsync
chainAsync is a Function
Calls all functions in an array
chainAsync is a Function
Calls all functions in an array
Testing chunk
@ -273,18 +273,18 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing createElement
createElement is a Function
Tested by @chalarangelo on 16/02/2018
createElement is a Function
Tested by @chalarangelo on 16/02/2018
Testing createEventHub
createEventHub is a Function
Tested by @chalarangelo on 16/02/2018
createEventHub is a Function
Tested by @chalarangelo on 16/02/2018
Testing currentURL
currentURL is a Function
Tested by @chalarangelo on 16/02/2018
currentURL is a Function
Tested by @chalarangelo on 16/02/2018
Testing curry
@ -315,13 +315,13 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing defaults
defaults is a Function
Assigns default values for undefined properties
defaults is a Function
Assigns default values for undefined properties
Testing defer
defer is a Function
Tested by @chalarangelo on 16/02/2018
defer is a Function
Tested by @chalarangelo on 16/02/2018
Testing degreesToRads
@ -541,6 +541,8 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing fuzzySearch
√ fuzzySearch is a Function
√ Provided examples work
√ Provided examples work
Testing gcd
@ -575,13 +577,13 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing getScrollPosition
getScrollPosition is a Function
Tested by @chalarangelo on 16/02/2018
getScrollPosition is a Function
Tested by @chalarangelo on 16/02/2018
Testing getStyle
getStyle is a Function
Tested by @chalarangelo on 16/02/2018
getStyle is a Function
Tested by @chalarangelo on 16/02/2018
Testing getType
@ -610,13 +612,13 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing hasFlags
hasFlags is a Function
Tested by @chalarangelo on 16/02/2018
hasFlags is a Function
Tested by @chalarangelo on 16/02/2018
Testing hashBrowser
hashBrowser is a Function
Tested by @chalarangelo on 16/02/2018
hashBrowser is a Function
Tested by @chalarangelo on 16/02/2018
Testing hashNode
@ -643,8 +645,8 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing hide
hide is a Function
Tested by @chalarangelo on 16/02/2018
hide is a Function
Tested by @chalarangelo on 16/02/2018
Testing howManyTimes
@ -993,6 +995,10 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
√ Returns the least common multiple of two or more numbers.
√ Returns the least common multiple of two or more numbers.
Testing levenshteinDistance
√ levenshteinDistance is a Function
Testing longestItem
√ longestItem is a Function
@ -1090,8 +1096,8 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing mostPerformant
mostPerformant is a Function
Tested by @chalarangelo on 16/02/2018
mostPerformant is a Function
Tested by @chalarangelo on 16/02/2018
Testing negate
@ -1100,11 +1106,11 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing none
none is a Function
Returns true for arrays with no truthy values
Returns false for arrays with at least one truthy value
Returns true with a predicate function
Returns false with predicate function
none is a Function
Returns true for arrays with no truthy values
Returns false for arrays with at least one truthy value
Returns true with a predicate function
Returns false with predicate function
Testing nthArg
@ -1136,8 +1142,8 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing off
off is a Function
Tested by @chalarangelo on 16/02/2018
off is a Function
Tested by @chalarangelo on 16/02/2018
Testing omit
@ -1151,18 +1157,18 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing on
on is a Function
Tested by @chalarangelo on 16/02/2018
on is a Function
Tested by @chalarangelo on 16/02/2018
Testing once
onUserInputChange is a Function
Tested by @chalarangelo on 16/02/2018
once is a Function
Tested by @chalarangelo on 16/02/2018
Testing onUserInputChange
once is a Function
Tested by @chalarangelo on 16/02/2018
onUserInputChange is a Function
Tested by @chalarangelo on 16/02/2018
Testing orderBy
@ -1304,10 +1310,10 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing randomHexColorCode
randomHexColorCode is a Function
should be equal
The color code starts with "#"
The color code contains only valid hex-digits
randomHexColorCode is a Function
should be equal
The color code starts with "#"
The color code contains only valid hex-digits
Testing randomIntArrayInRange
@ -1440,8 +1446,8 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing setStyle
setStyle is a Function
Tested by @chalarangelo on 16/02/2018
setStyle is a Function
Tested by @chalarangelo on 16/02/2018
Testing shallowClone
@ -1451,8 +1457,8 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing show
show is a Function
Tested by @chalarangelo on 16/02/2018
show is a Function
Tested by @chalarangelo on 16/02/2018
Testing shuffle
@ -1593,17 +1599,18 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing throttle
throttle is a Function
Tested by @chalarangelo on 16/02/2018
throttle is a Function
Tested by @chalarangelo on 16/02/2018
Testing times
timeTaken is a Function
✔ Tested by @chalarangelo on 16/02/2018
times is a Function
√ Runs a function the specified amount of times
Testing timeTaken
√ timeTaken is a Function
√ Tested by @chalarangelo on 16/02/2018
Testing toCamelCase
@ -1633,6 +1640,7 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing toggleClass
√ toggleClass is a Function
√ Tested by @chalarangelo on 16/02/2018
Testing toKebabCase
@ -1664,8 +1672,18 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing toSafeInteger
toggleClass is a Function
✔ Tested by @chalarangelo on 16/02/2018
toSafeInteger is a Function
√ Number(toSafeInteger(3.2)) is a number
√ Converts a value to a safe integer
√ toSafeInteger('4.2') returns 4
√ toSafeInteger(4.6) returns 5
√ toSafeInteger([]) returns 0
√ isNaN(toSafeInteger([1.5, 3124])) is true
√ isNaN(toSafeInteger('string')) is true
√ isNaN(toSafeInteger({})) is true
√ isNaN(toSafeInteger()) is true
√ toSafeInteger(Infinity) returns 9007199254740991
√ toSafeInteger(3.2) takes less than 2s to run
Testing toSnakeCase
@ -1888,17 +1906,17 @@ Test log for: Sat Feb 17 2018 20:23:50 GMT+0000 (UTC)
Testing zipWith
zipWith is a Function
✔ Sends a GET request
✔ Sends a POST request
✔ Runs the function provided
✔ Runs promises in series
✔ Works as expecting, passing arguments properly
Works with multiple promises
zipWith is a Function
√ Runs the function provided
√ Runs promises in series
√ Works as expecting, passing arguments properly
√ Sends a GET request
√ Sends a POST request
Works with multiple promises
total: 970
passing: 970
duration: 2.4s
total: 974
passing: 974
duration: 2.9s