Permalink
Browse files

array detection was too permissive, was mathcing on strings (duh)

  • Loading branch information...
1 parent 1f6f819 commit d848744da258aa9e299befa451d686065192dc8b @sconover committed Feb 5, 2011
Showing with 13 additions and 1 deletion.
  1. +1 −1 lib/collection_functions.js
  2. +4 −0 notes.txt
  3. +8 −0 spec/collection/flatten_spec.js
View
2 lib/collection_functions.js
@@ -17,7 +17,7 @@ CollectionFunctions = (function(){
equals:function(a,b){return a == b},
newCollection:function(){return []},
append:function(array, item){ array.push(item) },
- isCollection:function(thing){ return typeof thing.length != "undefined" },
+ isCollection:function(thing){ return typeof thing.length != "undefined" && typeof thing.push != "undefined" },
size:function(array){ return array.length },
sort:function(array){ return [].concat(array).sort() },
concat:function(){
View
4 notes.txt
@@ -9,6 +9,10 @@ efficiency:
- need to implement sort and make the set-style methods not be n^2
- collection-level equality feature ([1,2] == [1,2]), in by default for arrays (otherwise equality is N)
+hash?
+ feature - hashcode
+ set?
+
bang methods do work in place
you need in-place editing capability to do things in place
append is an example of in-place editing
View
8 spec/collection/flatten_spec.js
@@ -9,6 +9,14 @@ describe("flatten", function() {
expect(result).toEqual([1,2,3,4,5,6,7])
})
+ it("other cases", function(){
+ expect(fArr.flatten([[[3]]])).toEqual([3])
+ expect(fArr.flatten([[[]]])).toEqual([])
+ expect(fArr.flatten([])).toEqual([])
+
+ expect(fArr.flatten([[['Jane']]])).toEqual(['Jane'])
+ })
+
it("returns the same collection if there's nothing to do", function(){
var result = fArr.flatten([1,2,3,4,5,6,7])
expect(result).toEqual([1,2,3,4,5,6,7])

0 comments on commit d848744

Please sign in to comment.