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
def pick_bank_score | |
# TODO: Use Random to get a new random score | |
# rand(16...21) doesn't include 21 | |
rand (16..21) # includes 21 | |
end | |
def pick_player_card | |
# TODO: Use Random to get a new random card | |
rand(1..11) | |
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
def acronymize(string) | |
# TODO: write a method that returns | |
# the acronym for the given string | |
# 1. Split the string into words | |
# 2. Take the first letter of each word | |
# & capitalize them | |
# 3. Join the first letters together | |
# 4. Return the result | |
words = string.split(" ") |
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
# Ranges | |
range_1 = (1..10).to_a # includes the last element | |
p range_1 | |
range_2 = (1...10).to_a # excludes the last element | |
p range_2 | |
# Arrays |
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
def acronymize(sentence) | |
# map => [] | |
# applies transformations to elements | |
# 1. split sentence into words (list use Array) | |
words = sentence.split | |
# 2. Go through/Take each word | |
# and take/grab the first letter (capitalize) | |
initials = words.map { |word| word[0].capitalize } | |
# 3. Join words into a single sentence |
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
# Player begins with 100$ | |
# if player wins 50$ | |
# otherwise loses 10$ | |
# player = { wallet: 100 } | |
# list of a horses / race roster => Array | |
# ==== START LOOP ==== | |
# display list of horses | |
# ask the user for the winning horse | |
# store user choice |
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
require 'date' | |
require 'yaml' | |
PATTERN = /^(?<gender>[12])\s?(?<yob>\d{2})\s?(?<mob>0[1-9]|1[0-2])\s?(?<department>\d\d|2[AB])\s?\d{3}\s?\d{3}\s?(?<key>\d\d)$/ | |
# hash | |
DEPARTMENTS = YAML.load_file('./data/french_departments.yml') | |
def french_ssn(ssn) | |
return "The number is invalid" if ssn.empty? |
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
# add remote: true to form | |
<%= simple_form_for @model, remote: true do |f| %> | |
# ... | |
<%= f.button :submit %> | |
<% end %> | |
# controller receives ajax request | |
def create | |
# do something |
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
def acronymize(string) | |
# TODO: write a method that returns | |
# the acronym for the given string | |
# 1. Split the sentence into words | |
# 2. Grab the first letter of each word | |
# 3. Capitalize it | |
# 4. Join the first letters together | |
# 5. return the result | |
# gsub: string to replace , replace with |
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
# YIELD | |
def bigcount | |
(0..100000000).sort | |
end | |
def timer(callback) | |
start_time = Time.now |
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
def encrypt(sentence, permutation_level = -3) | |
return "" if sentence.empty? | |
alphabet = ("A".."Z").to_a | |
# 1. Split string into letters | |
letters = sentence.upcase.split("") | |
# 2. Go through each letter | |
result = "" | |
# letters.each do |letter| | |
# # 3. Find index in list of letters | |
# letter_index = alphabet.index(letter) |