Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use native map and forEach if available

  • Loading branch information...
commit f15ebb59fe3b2262b9aed6ba261debb42c28715d 1 parent ab83269
@marcuswestin authored
Showing with 6 additions and 1 deletion.
  1. +3 −1 each.js
  2. +3 −0  map.js
View
4 each.js
@@ -2,7 +2,9 @@ var isList = require('./isList')
module.exports = function each(items, fn) {
if (!items) { return }
- if (isList(items)) {
+ if (items.forEach == Array.prototype.forEach) {
+ items.forEach(fn)
+ } else if (isList(items)) {
for (var i=0; i < items.length; i++) {
fn(items[i], i)
}
View
3  map.js
@@ -3,6 +3,9 @@ var isList = require('./isList')
var isArray = require('./isArray')
module.exports = function map(obj, fn) {
+ if (!obj) { return null }
+ if (obj.map == Array.prototype.map) { return obj.map(fn) }
+
var result = isList(obj) ? new Array(obj.length) : {}
each(obj, function(val, key) {
result[key] = fn(val, key)
Please sign in to comment.
Something went wrong with that request. Please try again.