Skip to content

Commit

Permalink
Add isArray implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
timoxley committed Jan 15, 2014
1 parent ec221fb commit 01a83bf
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function toArray(collection) {
if (collection === null) return [null]
if (collection === window) return [window]
if (typeof collection === 'string') return [collection]
if (collection instanceof Array) return collection
if (isArray(collection)) return collection
if (typeof collection.length != 'number') return [collection]
if (typeof collection === 'function') return [collection]

Expand All @@ -25,3 +25,7 @@ module.exports = function toArray(collection) {
if (!arr.length) return []
return arr
}

function isArray(arr) {
return Object.prototype.toString.call(arr) === "[object Array]";
}

0 comments on commit 01a83bf

Please sign in to comment.