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,
// otherwise generate a group id.
var generateGroupId = function (items, pos) {
function generateGroupId (items, pos) {
var i, item, j, k, ref1, ref2, ref3
if (pos > 0) {
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|.
var indexOfItemById = function (items, id) {
var i, item, j, len
for (i = j = 0, len = items.length; j < len; i = ++j) {
item = items[i]
if (item.id === id) {
return i
}
function indexOfItemById (items, id) {
for (let idx = 0; idx < items.length; idx += 1) {
const item = items[idx]
if (item.id === id) return idx
}
return -1
}
// Returns the index of where to insert the item according to |position|.
var indexToInsertByPosition = function (items, position) {
function indexToInsertByPosition (items, position) {
var insertIndex
if (!position) {
return items.length