refactor indexOfItemById

This commit is contained in:
Shelley Vohr 2017-10-22 23:51:33 -04:00
parent 306b627090
commit b7ebee985b
No known key found for this signature in database
GPG key ID: F13993A75599653C

View file

@ -10,7 +10,7 @@ var nextGroupId = 0
// Search between separators to find a radio menu item and return its group id, // Search between separators to find a radio menu item and return its group id,
// otherwise generate a group id. // otherwise generate a group id.
var generateGroupId = function (items, pos) { function generateGroupId (items, pos) {
var i, item, j, k, ref1, ref2, ref3 var i, item, j, k, ref1, ref2, ref3
if (pos > 0) { if (pos > 0) {
for (i = j = ref1 = pos - 1; ref1 <= 0 ? j <= 0 : j >= 0; i = ref1 <= 0 ? ++j : --j) { for (i = j = ref1 = pos - 1; ref1 <= 0 ? j <= 0 : j >= 0; i = ref1 <= 0 ? ++j : --j) {
@ -37,19 +37,16 @@ var generateGroupId = function (items, pos) {
} }
// Returns the index of item according to |id|. // Returns the index of item according to |id|.
var indexOfItemById = function (items, id) { function indexOfItemById (items, id) {
var i, item, j, len for (let idx = 0; idx < items.length; idx += 1) {
for (i = j = 0, len = items.length; j < len; i = ++j) { const item = items[idx]
item = items[i] if (item.id === id) return idx
if (item.id === id) {
return i
}
} }
return -1 return -1
} }
// Returns the index of where to insert the item according to |position|. // Returns the index of where to insert the item according to |position|.
var indexToInsertByPosition = function (items, position) { function indexToInsertByPosition (items, position) {
var insertIndex var insertIndex
if (!position) { if (!position) {
return items.length return items.length