Skip to content

Instantly share code, notes, and snippets.

View dannysmith's full-sized avatar

Danny Smith dannysmith

View GitHub Profile
[
{
"id": "A1",
"title": "The Lean Startup",
"complete": false,
"progress": 45,
"finishedOn": "",
"author": "Eric Ries",
"rating": 0,
"tags": ["business", "tech"],
def reverse_alternate(string)
words = string.split(' ')
words.each_with_index { |word, i| word.reverse! if i.odd? }
return words.join(' ')
end
reverse_alternate('one two three four') #=> 'one owt three ruof'
def reverse_alternate(string)
# 1. Break the string down into an array of words.
words = string.split(' ')
# 2. Loop over each word in the array.
words.each_with_index do |word, index|
# - if the index is odd, change the word so it is reversed.
# - if the index is even, leave it as it is.
word.reverse! if index.odd?
def reverse_alternate(string)
# 1. Break the string down into an array of words.
words = string.split(' ')
# 2. Loop over each word in the array.
# - if the index is odd, change the word so it is reversed.
# - if the index is even, leave it as it is.
# 3. Join all the words in the array together so they are a string again, with spaces between them.
# 4. Return the new string we made.
end
def reverse_alternate(string)
# 1. Break the string down into an array of words.
# 2. Loop over each word in the array.
# - if the index is odd, change the word so it is reversed.
# - if the index is even, leave it as it is.
# 3. Join all the words in the array together so they are a string again, with spaces between them.
# 4. Return the new string we made.
end
reverse_alternate('one two three four') #=> 'one owt three ruof'
def reverse_alternate(string)
# 1. Break the string down into an array of words.
# 2. Loop over each word in the array.
# - if the index is odd, change the word so it is reversed.
# - if the index is even, leave it as it is.
# 3.
end
reverse_alternate('one two three four') #=> 'one owt three ruof'
def reverse_alternate(string)
# 1. Break the string down into an array of words.
# 2.
end
reverse_alternate('one two three four') #=> 'one owt three ruof'
def reverse_alternate(string)
#your code here
end
reverse_alternate('one two three four') #=> 'one owt three ruof'
class ValueObject
NotImplementedInSubclassError = Class.new(StandardError)
def initialize
raise NotImplementedInSubclassError, 'Value Objects must implement a constructor'
end
# This is not ideal, since it will fail if the object contains any instance variables that are not exposed via getter methods.
def ==(other)
return false unless self.class == other.class
require 'awesome_print'
class ExpectationTarget
def initialize(obj)
@object = obj
end
def to(matcher)
raise ArgumentError, 'Not a matcher' unless matcher.respond_to?(:matches?)
test_match(matcher.matches?(@object))