Skip to content

Commit 65cf10c

Browse files
committed
Relax the array restriction on _.insert (documentcloud#199)
1 parent fe7a2ed commit 65cf10c

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

docs/underscore.array.builders.js.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ _.cycle(5, [1,2,3]);
154154

155155
#### insert
156156

157-
Given an array, an index and a value, insert the value at this index in the array. The value that was previously at this index shifts one position up, together with any values that may come after it. `_.insert` modifies the array in place and also returns it. Useful shorthand for `Array.prototype.splice.call(array, index, 0, value)`.
157+
Given an array (or array-like object), an index and a value, insert the value at this index in the array. The value that was previously at this index shifts one position up, together with any values that may come after it. `_.insert` modifies the array in place and also returns it. Useful shorthand for `Array.prototype.splice.call(array, index, 0, value)`.
158158

159159
```javascript
160160
var array = [1, 2, 3];

underscore.array.builders.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@
198198
},[]);
199199
},_.map(arguments[0],function(i){return [i];}));
200200
},
201-
201+
202202
// Inserts an item in an array at the specific index mutating the original
203203
// array and returning it.
204204
insert: function(array, index, item){
205-
if (!_.isArray(array)) throw new TypeError('Expected an array as the first argument');
205+
if (!_.isNumber(array.length)) throw new TypeError('Expected an array-like object as the first argument');
206206
splice.call(array, index, 0, item);
207207
return array;
208208
}

0 commit comments

Comments
 (0)