Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

util: Make less function required for lower_bound.

Priyank Patelc37cde1202f0
diff --git a/frontend_tests/node_tests/util.js b/frontend_tests/node_tests/util.js
index bcba3d9b7f6..11fab0fea67 100644
--- a/frontend_tests/node_tests/util.js
+++ b/frontend_tests/node_tests/util.js
@@ -45,14 +45,7 @@ run_test("is_pm_recipient", () => {
});
run_test("lower_bound", () => {
- let arr = [10, 20, 30, 40, 50];
- assert.equal(util.lower_bound(arr, 5), 0);
- assert.equal(util.lower_bound(arr, 10), 0);
- assert.equal(util.lower_bound(arr, 15), 1);
- assert.equal(util.lower_bound(arr, 50), 4);
- assert.equal(util.lower_bound(arr, 55), 5);
-
- arr = [{x: 10}, {x: 20}, {x: 30}];
+ const arr = [{x: 10}, {x: 20}, {x: 30}, {x: 40}, {x: 50}];
function compare(a, b) {
return a.x < b;
@@ -61,6 +54,8 @@ run_test("lower_bound", () => {
assert.equal(util.lower_bound(arr, 5, compare), 0);
assert.equal(util.lower_bound(arr, 10, compare), 0);
assert.equal(util.lower_bound(arr, 15, compare), 1);
+ assert.equal(util.lower_bound(arr, 50, compare), 4);
+ assert.equal(util.lower_bound(arr, 55, compare), 5);
});
run_test("same_recipient", () => {
diff --git a/static/js/util.js b/static/js/util.js
index fb97234fb90..63cc2ad2fff 100644
--- a/static/js/util.js
+++ b/static/js/util.js
@@ -14,15 +14,10 @@ export function random_int(min, max) {
// array[i] < value
// for some i and false otherwise.
//
-// Usage: lower_bound(array, value, [less])
+// Usage: lower_bound(array, value, less)
export function lower_bound(array, value, less) {
let first = 0;
const last = array.length;
- if (less === undefined) {
- less = function (a, b) {
- return a < b;
- };
- }
let len = last - first;
let middle;