all files / scour/utilities/ each.js

100% Statements 18/18
87.5% Branches 7/8
100% Functions 1/1
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30            83×   75× 75× 75×   75× 40×   35× 35× 78×       36×        
/**
 * each : each(list, fn)
 * Iterates through `list` (an array or an object). This is useful when dealing
 * with NodeLists like `document.querySelectorAll`.
 */
 
function each (list, fn) {
  if (!list) return
 
  var i
  var len = list.length
  var idx
 
  if (typeof len === 'number') {
    if (each.native) return each.native.call(list, fn)
    for (i = 0; i < len; i++) fn(list[i], i, i)
  } else {
    idx = 0
    for (i in list) {
      Eif (list.hasOwnProperty(i)) fn(list[i], i, idx++)
    }
  }
 
  return list
}
 
each.native = Array.prototype.forEach
 
module.exports = each