Merge pull request #220 from bjorn/count_predicate

Added Sequence.count(predicate)
This commit is contained in:
Bob Nystrom
2015-03-23 07:35:17 -07:00
7 changed files with 52 additions and 2 deletions
+6
View File
@@ -0,0 +1,6 @@
var a = [1, 2, 3]
IO.print(a.count {|x| x > 3 }) // expect: 0
IO.print(a.count {|x| x > 1 }) // expect: 2
IO.print([].count {|x| true }) // expect: 0
@@ -0,0 +1,3 @@
var a = [1, 2, 3]
IO.print(a.count {|x| "truthy" }) // expect: 3
@@ -0,0 +1,3 @@
var a = [1, 2, 3]
a.count("string") // expect runtime error: String does not implement 'call(_)'.