Browse Source

optimize splitList() function with splice() function

feat-mydojo_upgrade_explorer
kenshin-samourai 5 years ago
parent
commit
d01b713ba2
  1. 18
      lib/util.js

18
lib/util.js

@ -101,20 +101,14 @@ class Util {
* Splits a list into a list of lists each with maximum length LIMIT
*/
static splitList(list, limit) {
if (list.length <= limit) {
if (list.length <= limit)
return [list]
} else {
const lists = []
// How many lists to create?
const count = Math.ceil(list.length / limit)
// How many elements per list (max)?
const els = Math.ceil(list.length / count)
for (let i=0; i < count; i++) {
lists.push(list.slice(i * els, (i+1) * els))
}
return lists
const lists = []
while (list.length) {
lists.push(list.splice(0, limit))
}
return lists
}
/**

Loading…
Cancel
Save