Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

splice feature requirements

  • Loading branch information...
commit 724cf69d09184df1776020bc34078b3178389d3e 1 parent e940a91
@sconover authored
Showing with 28 additions and 1 deletion.
  1. +1 −1  lib/collection_functions.js
  2. +27 −0 spec/splice_spec.js
View
2  lib/collection_functions.js
@@ -359,6 +359,7 @@ CollectionFunctions = (function(){
spliceInCollection,
slice(mainCollection, [insertAtIndex + overwriteLength, -1]))
}
+ if (functionsForExport.concat && functionsForExport.slice) functionsForExport.splice = splice
function inspect(collection) {
var strings = []
@@ -380,7 +381,6 @@ CollectionFunctions = (function(){
}
var more = {
- splice:splice,
without:without
}
View
27 spec/splice_spec.js
@@ -13,6 +13,33 @@ describe("splice", function() {
var result = fArr.splice([5,6,777,888,999,10,11], [7,8,9], 2, 3)
expect(result).toEqual([5,6,7,8,9,10,11])
})
+
+ describe("feature requirements", function(){
+
+ it("requires newCollection, append, and iterator", function(){
+ expect(CollectionFunctions({}).functions.
+ splice).toBeUndefined()
+
+ expect(CollectionFunctions({iterator:fArr.iterator}).functions.
+ splice).toBeUndefined()
+
+ expect(CollectionFunctions({newCollection:function(){return []},
+ iterator:fArr.iterator,
+ append:function(array, item){array.push(item)}}).functions.
+ splice).toBeDefined()
+ })
+
+ it("works with newCollection, append, and iterator", function(){
+ var fMin = CollectionFunctions({iterator:fArr.iterator,
+ newCollection:function(){return []},
+ append:function(array, item){array.push(item)}}).functions
+
+ var result = fMin.splice([5,6,10,11], [7,8,9], 2)
+ expect(result).toEqual([5,6,7,8,9,10,11])
+ })
+
+ })
+
})
Please sign in to comment.
Something went wrong with that request. Please try again.