find-by-words
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -13,3 +13,12 @@ /* | ||
})('findByWords', this, function (name, context) { | ||
var findByWords = function(a, word) { | ||
var _isEqual = function(word1, word2, caseSensitive) { | ||
if (caseSensitive) { | ||
return word1.toLowerCase() == word2.toLowerCase(); | ||
} | ||
return word1 == word2; | ||
}; | ||
var findByWords = function(a, word, caseSensitive) { | ||
var size = word.length; | ||
@@ -25,3 +34,3 @@ var first = 0; | ||
if (wordPart == word) { | ||
if (_isEqual(wordPart, word, caseSensitive)) { | ||
found = true; | ||
@@ -31,7 +40,7 @@ output.push(a[middle]); | ||
while (a[--_middle] && a[_middle].slice(0, size) == word) { | ||
while (a[--_middle] && _isEqual(a[_middle].slice(0, size), word, caseSensitive)) { | ||
output.push(a[_middle]); | ||
} | ||
while (a[++middle] && a[middle].slice(0, size) == word) { | ||
while (a[++middle] && _isEqual(a[middle].slice(0, size), word, caseSensitive)) { | ||
output.push(a[middle]); | ||
@@ -38,0 +47,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"repository": "evandrolg/find-by-words", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"main": "search-by-words.js", | ||
@@ -8,0 +8,0 @@ "keywords": [ |
@@ -12,7 +12,12 @@ # find-by-words | ||
## Parameters | ||
* **wordsList** <code>Array</code> | ||
* **word** <code>String</code> | ||
* **caseSensitive** <code>Boolean</code> (<code>false</code> by default) | ||
## How to use? | ||
```js | ||
findByWords(['python', 'ruby', 'java', 'javascript', 'lua'], 'java'); | ||
findByWords(['python', 'ruby', 'java', 'javascript', 'lua'], 'Java', true); | ||
// output: ['java', 'javascript'] | ||
``` | ||
19
test.js
@@ -6,4 +6,4 @@ var assert = require('assert'); | ||
var verifyOutput = function(list, word, expected) { | ||
var output = findByWords(list, word); | ||
var verifyOutput = function(list, word, expected, caseSensitive) { | ||
var output = findByWords(list, word, caseSensitive); | ||
assert(expected.every((v, i) => v == output[i])); | ||
@@ -20,2 +20,17 @@ }; | ||
}); | ||
it('should return an array with two items using case sensitive comparation', function() { | ||
verifyOutput(['python', 'ruby', 'Java', 'JavaScript', 'lua'], | ||
'java', ['Java', 'JavaScript'], true); | ||
}); | ||
it('should return an empty array with because caseSenstive parameter is undefined', function() { | ||
verifyOutput(['python', 'ruby', 'Java', 'JavaScript', 'lua'], | ||
'java', []); | ||
}); | ||
it('should return an empty array with because caseSenstive parameter is false', function() { | ||
verifyOutput(['python', 'ruby', 'Java', 'JavaScript', 'lua'], | ||
'java', [], false); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5037
73
23