diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2022-11-21 21:48:31 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2022-11-21 21:48:31 -0400 |
commit | ba2751eae00c4bcf10403edbd549ca70dc316cab (patch) | |
tree | 492537e39b268dd1991bc85ffb2e4c666ff03536 /src/util/wiki-data.js | |
parent | 860b9fbf12315362d2c33864521c3f081fd66545 (diff) |
new "empty" sugar.js util
Diffstat (limited to 'src/util/wiki-data.js')
-rw-r--r-- | src/util/wiki-data.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js index 97ffab76..b0b0b2e0 100644 --- a/src/util/wiki-data.js +++ b/src/util/wiki-data.js @@ -2,6 +2,8 @@ // Utility functions for interacting with wiki data. +import {empty} from './sugar.js'; + // Generic value operations export function getKebabCase(name) { @@ -16,9 +18,11 @@ export function getKebabCase(name) { } export function chunkByConditions(array, conditions) { - if (array.length === 0) { + if (empty(array)) { return []; - } else if (conditions.length === 0) { + } + + if (empty(conditions)) { return [array]; } @@ -469,7 +473,7 @@ export function getNewAdditions(numAlbums, {wikiData}) { // Then cycle over that sorted array, adding one al8um from each to // the main array until we've run out or have met the target num8er // of al8ums. - while (groupArray.length) { + while (!empty(groupArray)) { let j = 0; while (j < groupArray.length) { const entry = groupArray[j]; @@ -485,10 +489,10 @@ export function getNewAdditions(numAlbums, {wikiData}) { break outerLoop; } - if (entry.length) { - j++; - } else { + if (empty(entry)) { groupArray.splice(j, 1); + } else { + j++; } } } |