(collection, callback)
| 1 | import isObject from './is-object' |
| 2 | |
| 3 | export default function each(collection, callback) { |
| 4 | if (isObject(collection)) { |
| 5 | const keys = Object.keys(collection) |
| 6 | return keys.forEach(key => callback(collection[key], key, collection)) |
| 7 | } |
| 8 | if (collection instanceof Array) { |
| 9 | return collection.forEach((item, i) => callback(item, i, collection)) |
| 10 | } |
| 11 | throw new TypeError('Expected either an array or object literal.') |
| 12 | } |
no test coverage detected