collections
Advanced tools
Comparing version 5.1.2 to 5.1.3
@@ -1,2 +0,13 @@ | ||
## v5.1 | ||
## v5.1.3 | ||
- Fix Sorted-Set.reduceRight #206 | ||
- Fix sorted array incomparable values bugs #171 | ||
## v5.1.2 | ||
- Pass the this.sort arguments to this.sorted. #191 | ||
- Add npm run build via browserify #190 | ||
## v5.1.1 | ||
- Fix SortedArray handles incomparable values poorly #27 | ||
## v5.1.0 | ||
- Addresses a bug with Array#find and deprecate find|findLast in favor of findValue|findLastValue API in collections. | ||
@@ -3,0 +14,0 @@ |
{ | ||
"name": "collections", | ||
"version": "5.1.2", | ||
"version": "5.1.3", | ||
"description": "data structures with idiomatic JavaScript collection interfaces", | ||
@@ -5,0 +5,0 @@ "homepage": "http://www.collectionsjs.com", |
@@ -56,2 +56,18 @@ "use strict"; | ||
function determineIncomparableRange(index, array, value, compare, equals) { | ||
// Return the inclusive start and end indices of the incomparable streak containing value. | ||
var start = index; | ||
var end = index; | ||
while (start > 0 && compare(value, array[start - 1]) === 0) { | ||
start--; | ||
} | ||
while (end < array.length - 1 && compare(value, array[end + 1]) === 0) { | ||
end++; | ||
} | ||
return {start: start, end: end}; | ||
} | ||
function searchFirst(array, value, compare, equals) { | ||
@@ -62,10 +78,11 @@ var index = search(array, value, compare); | ||
} else { | ||
while (index > 0 && equals(value, array[index - 1])) { | ||
index--; | ||
var range = determineIncomparableRange(index, array, value, compare, equals); | ||
for (var i = range.start; i <= range.end; i++) { | ||
if (equals(value, array[i])) { | ||
return i; | ||
} | ||
} | ||
if (!equals(value, array[index])) { | ||
return -1; | ||
} else { | ||
return index; | ||
} | ||
return -1; | ||
} | ||
@@ -79,10 +96,11 @@ } | ||
} else { | ||
while (index < array.length - 1 && equals(value, array[index + 1])) { | ||
index++; | ||
var range = determineIncomparableRange(index, array, value, compare, equals); | ||
for (var i = range.end; i >= range.start; i--) { | ||
if (equals(value, array[i])) { | ||
return i; | ||
} | ||
} | ||
if (!equals(value, array[index])) { | ||
return -1; | ||
} else { | ||
return index; | ||
} | ||
return -1; | ||
} | ||
@@ -117,4 +135,4 @@ } | ||
} | ||
var index = search(this.array, value, this.contentCompare); | ||
return index >= 0 && this.contentEquals(this.array[index], value); | ||
var index = searchFirst(this.array, value, this.contentCompare, this.contentEquals); | ||
return index !== -1; | ||
}; | ||
@@ -121,0 +139,0 @@ |
@@ -603,3 +603,3 @@ "use strict"; | ||
if (this.right) { | ||
basis = this.right.reduce(callback, basis, index, thisp, tree, depth + 1); | ||
basis = this.right.reduceRight(callback, basis, index, thisp, tree, depth + 1); | ||
index -= this.right.length; | ||
@@ -610,3 +610,3 @@ } | ||
if (this.left) { | ||
basis = this.left.reduce(callback, basis, index, thisp, tree, depth + 1); | ||
basis = this.left.reduceRight(callback, basis, index, thisp, tree, depth + 1); | ||
} | ||
@@ -613,0 +613,0 @@ return basis; |
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
295741
7753