6 kyu

Iterate function

55 of 116phaul

Description:

Write the method Object#iterate that given an object takes a block as argument and an optional count n.

If n is given it returns an array of length n where each element can obtained by the successive application of the block on the object, starting with the object.

If n is not given, it returns an Enumerator that yields the successive application of the block on the object indefinitely.

Example:

'str'.iterate(3) {|s| s * 2 } # => ["str", "strstr", "strstrstrstr"]
"str".iterate( s => s+s , 3 ) // => ["str", "strstr", "strstrstrstr"]
Functional Programming
Fundamentals

More By Author:

Check out these other kata created by phaul

Stats:

CreatedSep 12, 2017
PublishedSep 12, 2017
Warriors Trained661
Total Skips21
Total Code Submissions2075
Total Times Completed116
Ruby Completions55
JavaScript Completions62
Total Stars28
% of votes with a positive feedback rating82% of 41
Total "Very Satisfied" Votes30
Total "Somewhat Satisfied" Votes7
Total "Not Satisfied" Votes4
Total Rank Assessments4
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • phaul Avatar
  • JohanWiltink Avatar
  • ZED.CWT Avatar
Ad