js: Convert _.reduce to less convoluted code.

reduce is almost never a better solution than the alternatives.  Avoid
it.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2020-02-07 21:17:38 -08:00
committed by Tim Abbott
parent 050915c46c
commit e1cf5e4630
3 changed files with 8 additions and 14 deletions

View File

@@ -93,7 +93,8 @@ exports.create = function ($container, list, opts) {
const slice = meta.filtered_list.slice(meta.offset, meta.offset + load_count);
const finish = blueslip.start_timing('list_render ' + opts.name);
const html = _.reduce(slice, function (acc, item) {
let html = "";
for (const item of slice) {
let _item = opts.modifier(item);
// if valid jQuery selection, attempt to grab all elements within
@@ -116,9 +117,9 @@ exports.create = function ($container, list, opts) {
_item = _item.outerHTML;
}
// return the modified HTML or nothing if corrupt (null, undef, etc.).
return acc + (_item || "");
}, "");
// append the HTML or nothing if corrupt (null, undef, etc.).
html += _item || "";
}
finish();