Travis build: 1751 [cron]
This commit is contained in:
5
test/isSimilar/isSimilar.js
Normal file
5
test/isSimilar/isSimilar.js
Normal file
@ -0,0 +1,5 @@
|
||||
const isSimilar = (pattern, str) =>
|
||||
[...str].reduce(
|
||||
(matchIndex, char) => char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() ? matchIndex + 1 : matchIndex, 0
|
||||
) === pattern.length ? true : false;
|
||||
module.exports = isSimilar;
|
||||
13
test/isSimilar/isSimilar.test.js
Normal file
13
test/isSimilar/isSimilar.test.js
Normal file
@ -0,0 +1,13 @@
|
||||
const test = require('tape');
|
||||
const isSimilar = require('./isSimilar.js');
|
||||
|
||||
test('Testing isSimilar', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof isSimilar === 'function', 'isSimilar is a Function');
|
||||
//t.deepEqual(isSimilar(args..), 'Expected');
|
||||
//t.equal(isSimilar(args..), 'Expected');
|
||||
//t.false(isSimilar(args..), 'Expected');
|
||||
//t.throws(isSimilar(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
@ -1,15 +1,15 @@
|
||||
const levenshteinDistance = (string1,string2) => {
|
||||
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]);
|
||||
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(let i = 1;i <= string2.length;i++){
|
||||
for(let j = 1;j<=string1.length; j++){
|
||||
for(let i = 1; i <= string2.length; i++){
|
||||
for(let 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);
|
||||
matrix[i][j] = Math.min(matrix[i-1][j-1]+1, matrix[i][j-1]+1, matrix[i-1][j]+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
const pad = (string, length = 8, char = ' ') =>
|
||||
string.padStart((string.length + length) / 2, char).padEnd(length, char);
|
||||
module.exports = pad;
|
||||
const pad = (str, length, char = ' ') =>
|
||||
str.padStart((str.length + length) / 2, char).padEnd(length, char);
|
||||
module.exports = pad;
|
||||
@ -1,9 +1,6 @@
|
||||
const sortedLastIndex = (arr, n) => {
|
||||
const isDescending = arr[0] > arr[arr.length - 1];
|
||||
const index = arr
|
||||
.map((val, i) => [i, val])
|
||||
.reverse()
|
||||
.findIndex(el => (isDescending ? n <= el[1] : n >= el[1]));
|
||||
const index = arr.reverse().findIndex(el => (isDescending ? n <= el : n >= el));
|
||||
return index === -1 ? 0 : arr.length - index - 1;
|
||||
};
|
||||
module.exports = sortedLastIndex;
|
||||
@ -2,9 +2,9 @@ const sortedLastIndexBy = (arr, n, fn) => {
|
||||
const isDescending = fn(arr[0]) > fn(arr[arr.length - 1]);
|
||||
const val = fn(n);
|
||||
const index = arr
|
||||
.map((val, i) => [i, fn(val)])
|
||||
.map(fn)
|
||||
.reverse()
|
||||
.findIndex(el => (isDescending ? val <= el[1] : val >= el[1]));
|
||||
.findIndex(el => (isDescending ? val <= el : val >= el));
|
||||
return index === -1 ? 0 : arr.length - index;
|
||||
};
|
||||
module.exports = sortedLastIndexBy;
|
||||
3800
test/testlog
3800
test/testlog
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user