refactor indexOfItemById
This commit is contained in:
parent
306b627090
commit
b7ebee985b
1 changed files with 6 additions and 9 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue