This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RockPaperScissors | |
| def hand(g1, g2) | |
| g1.play_against(g2) | |
| end | |
| end | |
| class Rock | |
| def play_against(other) | |
| other.play_against_rock(self) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var makeSubstitute = function (substitutionDescriptions) { | |
| var substituteOne = (function () { | |
| var substitutions = [], i; | |
| function makeSubstitution (pred, replacement) { | |
| return function substituteNumber(acc, number) { | |
| if ( pred(number) ) { | |
| acc += replacement; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe("FizzBuzz", function () { | |
| var fizzBuzzSubstitute; | |
| beforeEach(function () { | |
| fizzBuzzSubstitute = makeSubstitute([ | |
| { pred: function(number) {return number % 3 == 0;}, | |
| replacement: "Fizz"}, | |
| { pred: function(number) {return number % 5 == 0;}, | |
| replacement: "Buzz"} | |
| ]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| std::vector<std::string> NumbersExtractor::filterOutNotNumericTokens(const std::vector<std::string> & tokens) const { | |
| std::vector<std::string> numericTokens; | |
| for (unsigned int i = 0; i < tokens.size(); ++i) { | |
| std::string token = tokens[i]; | |
| if (isNotAnInteger(token)) { | |
| continue; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| std::vector<std::string> NumbersExtractor::filterOutNotNumericTokens(const std::vector<std::string> & tokens) const { | |
| std::vector<std::string> numericTokens; | |
| std::copy_if(tokens.begin(), tokens.end(), | |
| std::back_inserter(numericTokens), | |
| StringUtils::isAnInteger); | |
| return numericTokens; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| std::vector<int> NumbersFilter::ignoreTooBig(const std::vector<int> & numbers) const { | |
| std::vector<int> filteredNumbers; | |
| for (unsigned int i = 0; i < numbers.size(); ++i) { | |
| if (notTooBig(numbers[i])) { | |
| filteredNumbers.push_back(numbers[i]); | |
| } | |
| } | |
| return filteredNumbers; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| std::vector<int> NumbersFilter::ignoreTooBig(const std::vector<int> & numbers) const { | |
| std::vector<int> filteredNumbers; | |
| std::copy_if(numbers.begin(), numbers.end(), | |
| std::back_inserter(filteredNumbers), | |
| [](const int number) { return !(number > 1000); }); | |
| return filteredNumbers; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bool notTooBig(int number); | |
| std::vector<int> NumbersFilter::ignoreTooBig(const std::vector<int> & numbers) const { | |
| std::vector<int> filteredNumbers; | |
| std::copy_if(numbers.begin(), numbers.end(), | |
| std::back_inserter(filteredNumbers), | |
| notTooBig); | |
| return filteredNumbers; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| std::vector<int> NumbersFilter::ignoreTooBig(const std::vector<int> & numbers) const { | |
| std::vector<int> filteredNumbers; | |
| std::copy_if(numbers.begin(), numbers.end(), | |
| std::back_inserter(filteredNumbers), | |
| std::bind1st(std::mem_fun(&NumbersFilter::notTooBig), this)); | |
| return filteredNumbers; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace VectorUtils { | |
| template<typename T, typename Function> | |
| std::vector<T> filter(const std::vector<T> & original, Function pred) { | |
| std::vector<T> filtered; | |
| std::copy_if(original.begin(), original.end(), | |
| std::back_inserter(filtered), | |
| pred); |