This file contains 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 ints_only?(arr) | |
res = true | |
arr.map { |item| res = res && item.is_a?(Integer) ? true : false } | |
res | |
end | |
def array_flatten(arr) | |
while !ints_only?(arr) do | |
new_arr = Array.new | |
arr.map{ |item| |
This file contains 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 most_common_letter(string) | |
h = Hash.new | |
characters = string.chars.each do |c| | |
if (h[c].nil?) then | |
h[c] = 1 | |
else | |
h[c] = h[c]+1 | |
end | |
end | |
maxk = nil |
This file contains 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 most_common_letter(string) | |
h = Hash.new | |
string.chars.sort.each do |c| | |
h[c] = 0 if (h[c].nil?) | |
h[c] = h[c] + 1 | |
end | |
maxk = nil | |
maxv = -1 | |
mk = h.keys | |
mk.each do |k| |
This file contains 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 most_common_letter(string) | |
counts = Hash.new(0) | |
string.each_char {|c| counts[c] += 1 } | |
counts.max_by{|k,v| v} | |
end |
This file contains 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 alfa | |
alfa_variable = 1 | |
def beta | |
beta_variable = 2 | |
puts 'Method beta' | |
end | |
puts 'Method alfa' | |
puts alfa_variable |
This file contains 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 alfa | |
def beta | |
puts 'Method beta' | |
end | |
puts 'Method alfa' | |
beta | |
end |
This file contains 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 CustomersController < ApplicationController | |
def index | |
a = Customer.find(1) | |
b = Customer.where.not(id: 1).order(:name) | |
@customers = a + b | |
end | |
end |
This file contains 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 CustomersController < Applicationcontroller | |
def index | |
a = Customer.where(id: 1) | |
b = Customer.where.not(id: 1).order(:name) | |
@customers = a + b | |
end | |
end |
This file contains 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 CustomersController < ApplicationController | |
def index | |
@customers = Array.new | |
@customers.push(Customer.find(1)) | |
Customer.where.not(id: 1).order(:name).each{ |rec| @customers.push(rec) } | |
end | |
end |
This file contains 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 prime?(n) | |
res = true | |
(2..n-1).each{ |d| res = res && (not ((n%d)==0)) } | |
return res | |
end |
OlderNewer