Skip to content

Instantly share code, notes, and snippets.

def ladder_length(start_word, end_word, dictionary)
current_word = start_word
counter = 1
while !matching_letters(current_word, end_word, end_word.length - 1)
dictionary.each do |word|
if matching_letters(current_word, word, word.length - 1)
current_word = word
dictionary.delete(word)
counter += 1
end
class User
attr_reader :name, :todos
def initialize(name, password, gender)
@name = name
@password = password
@gender = gender
@todos = []
end
def create_todo(todo)
class Account
def initialize(pin)
@pin = pin
end
def can_access?(pin)
@pin == pin
end
def change_pin(pin, new_pin)
require 'json'
require 'pry'
data = JSON.parse(IO.read('movies_data.json'))
# cast_members = data['movies'][0]['abridged_cast']
# cast_member_names = cast_members.map{|member| member['name']}
all_cast_members = []
all_cast_characters = []
movies = data['movies']
require 'csv'
require 'pry'
file = 'lackp_starting_rosters.csv'
# Create an empty teams hash
teams = {}
# Open up the CSV and save it to the variable csv
csv = CSV.open(file, headers: true)

starting with the array numbers = [1,2,3,4,5,6,7,8,9]

  • double every number in the array
  • return the max value of the array
  • return the sum of the array
  • return the average of the array
  • return only the even numbers from the array
  • return every number above 6 from the array
  • return an array with only the odd numbers doubled. i.e. [2,2,6,4,10,6,14,8,18]
require 'pry'
VALID_INPUT = [1,2,3,4]
@products = []
def get_choice
puts 'Enter your selection'
choice = gets.chomp.to_i
validate_choice(choice)
scan(choice)
end
@wannabefro
wannabefro / 0_reuse_code.js
Created February 3, 2014 14:42
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
require 'benchmark'
@cache = Hash.new
def fibonacci_cache(n)
if t = @cache[n]
return t
end
if n <= 1
return 1
else
CSV.foreach(file,
headers: true,
converters: lambda{|s| s.gsub(',','').to_i ? s && s[0] =~ /\d/ : s}) do |row|
TownHealthRecords.find_or_initialize_by(geography: row['geography']) do |thr|
thr.population = row['population']
save!
end
end