Skip to content

Instantly share code, notes, and snippets.

class Anagram
attr_accessor :word
def initialize(word)
@word = word
end
def match(array)
@word = @word.split("").sort
array.select { |element| element.split("").sort == @word }
-- SQL Basic Syntax --
--initialize SQLite database w/ command line:
sqlite3 database_name.db
--helpful commands
.help -- list of commands
.tables -- see all tables
.mode column / .header on -- helpful for viewing
teams = {
thebest: {
colors: ["orange","purple"],
players:{
don: {
number: 1, shoe_size: 9, points: 5, rebounds: 6, assists: 7, steals: 8, blocks: 9, slam_dunks: 10
},
jon: {
number: 2, shoe_size: 8, points: 6, rebounds: 7, assists: 8, steals: 9, blocks: 10, slam_dunks: 11
teams = {
thebest: {
colors: ["orange","purple"],
players:{
don: {
number: 1, shoe_size: 9, points: 5, rebounds: 6, assists: 7, steals: 8, blocks: 9, slam_dunks: 10
},
jon: {
number: 2, shoe_size: 8, points: 6, rebounds: 7, assists: 8, steals: 9, blocks: 10, slam_dunks: 11
katz_deli = []
def take_a_number(deli_line, customer)
deli_line << customer
deli_line.index(customer) + 1
end
def now_serving(deli_line)
"Currently serving #{deli_line[0]}"
holiday_supplies = {
:winter => {
:christmas => ["Lights", "Wreath"],
:new_years => ["Party Hats"]
},
:summer => {
:forth_of_july => ["Fireworks", "BBQ"]
},
:fall => {
:thanksgiving => ["Turkey"]
apple_picker(["apple", "orange", "apple"]) #=> ["apple", "apple"]
apple_picker.map { |x| puts x}
apple_picker.select { |x| puts x }
def reverse_each_word(sentence)
sen_array = sentence.split(" ")
sen_rev = sen_array.map { |word| word.reverse}
sen_rev = sen_rev.join(" ")
end
puts reverse_each_word("Hello there, and how are you?")
def normalize_phone_number(number)
clean_num = number.gsub(/[^0-9]/, "")
clean_num.length != 10 ? number : "(#{clean_num[0,3]}) #{clean_num[3,3]}-#{clean_num[6,4]}"
end
def my_each(array)
i = 0
while i < array.length
yield(array[i])
i += 1
end
end
num_array = [5,6,7,8]