5 kyu

Lazy Repeater

5,419 of 8,050nklein

Description:

The makeLooper() function (or make_looper in your language) takes a string (of non-zero length) as an argument. It returns a function. The function it returns will return successive characters of the string on successive invocations. It will start back at the beginning of the string once it reaches the end.

For example:

var abc = makeLooper('abc');
abc(); // should return 'a' on this first call
abc(); // should return 'b' on this second call
abc(); // should return 'c' on this third call
abc(); // should return 'a' again on this fourth call
abc = makeLooper 'abc'
abc() # should return 'a' on this first call
abc() # should return 'b' on this second call
abc() # should return 'c' on this third call
abc() # should return 'a' again on this fourth call
Func<char> abc = Kata.MakeLooper("abc");
abc(); // should return 'a' on this first call
abc(); // should return 'b' on this second call
abc(); // should return 'c' on this third call
abc(); // should return 'a' again on this fourth call
abc = make_looper('abc')
abc() # should return 'a' on this first call
abc() # should return 'b' on this second call
abc() # should return 'c' on this third call
abc() # should return 'a' again on this fourth call
let mut abc = make_looper("abc");
abc(); // should return 'a' on this first call
abc(); // should return 'b' on this second call
abc(); // should return 'c' on this third call
abc(); // should return 'a' again on this fourth call
auto abc = makeLooper("abc");
abc(); // should return 'a' on this first call
abc(); // should return 'b' on this second call
abc(); // should return 'c' on this third call
abc(); // should return 'a' again on this fourth call

Different loopers should not affect each other, so be wary of unmanaged global state.

Iterators
Algorithms

Similar Kata:

Stats:

CreatedAug 2, 2013
PublishedAug 3, 2013
Warriors Trained13301
Total Skips1022
Total Code Submissions25704
Total Times Completed8050
JavaScript Completions5419
CoffeeScript Completions33
C# Completions490
Python Completions1399
Rust Completions150
Scala Completions47
TypeScript Completions522
C++ Completions198
Total Stars190
% of votes with a positive feedback rating93% of 604
Total "Very Satisfied" Votes534
Total "Somewhat Satisfied" Votes58
Total "Not Satisfied" Votes12
Ad
Contributors
  • nklein Avatar
  • jhoffner Avatar
  • SagePtr Avatar
  • iamphill Avatar
  • suic Avatar
  • myjinxin2015 Avatar
  • JohanWiltink Avatar
  • Souzooka Avatar
  • FArekkusu Avatar
  • Awesome A.D. Avatar
  • hobovsky Avatar
  • cplir-c Avatar
  • farhanaditya Avatar
  • yLaWy Avatar
  • o2001 Avatar
  • KayleighWasTaken Avatar
Ad