Permalink
Browse files

iterators

  • Loading branch information...
1 parent 11620b8 commit f804976ac12dca554575b460caacd6c9bab4a624 @nvijayap committed Dec 29, 2013
Showing with 32 additions and 0 deletions.
  1. +1 −0 trpl002.sh
  2. +25 −0 trpl003.rb
  3. +6 −0 trpl003.sh
View
@@ -1,3 +1,4 @@
+#!/bin/bash
cat trpl002.rb
View
@@ -0,0 +1,25 @@
+describe "iterators" do
+
+ it "each, map, select, inject" do
+
+ a = [3,2,1]
+
+ a[3] = a[2] -1
+ a.should == [3,2,1,0]
+
+ s = 0
+ a.each { |e| s += e }
+ s.should == 6
+
+ b = a.map { |e| e*e }
+ b.should == [9,4,1,0]
+
+ c = a.select { |e| e%2 == 0 }
+ c.should == [2,0]
+
+ d = a.inject { |sum, e| sum + e }
+ d.should == 6
+
+ end
+
+end
View
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+cat trpl003.rb
+
+rspec trpl003.rb
+

0 comments on commit f804976

Please sign in to comment.