Skip to content

Instantly share code, notes, and snippets.

Brice Lin bricejlin

View GitHub Profile
@bricejlin
bricejlin / mutliSum.js
Created Sep 3, 2015
multidimensional arr sum
View mutliSum.js
var multiArr = [[3,4],[4,1],[1,1]];
var sum = multiArr.map(function (arr) {
return arr.reduce(add, 0);
}).reduce(add, 0);
function add (a, b) {
return a + b;
}
View keybase.md

Keybase proof

I hereby claim:

  • I am bricejlin on github.
  • I am bricelin (https://keybase.io/bricelin) on keybase.
  • I have a public key whose fingerprint is 86E0 79D3 CC35 BBCC E86E 1BCA 24DA 2552 3448 07FF

To claim this, I am signing this object:

View reversedbinary.rb
num_to_reverse = ARGV.first.to_i
class ReversedBinary
def reverse_it(num)
reversed = num.to_s(2).reverse.to_i(2)
puts reversed
end
end
View crackle.rb
def crackle
(1..100).map do |i|
crackle = i % 3 == 0 ? 'Crackle' : nil
pop = i % 5 == 0 ? 'Pop' : nil
crackle || pop ? "#{crackle}#{pop}" : i
end
end
puts crackle
View match
pattern = ',*,foo,bar,baz'
path = 'cat/foo/bar/baz'
# rules for match method:
# - return boolean value
# - asterisks are wildcards
# - compare pattern and path
# - matching letter rated higher over asterisk
# - if same # of asterisks, prefer wildcards that appear further to right
View W3E9.rb
def reverse_string(string)
string.split(' ').reverse.join(' ')
end
puts reverse_string('this is a string!')
View W3E9.rb
string = 'this is a string'
arr = string.split(' ')
print arr.reverse.join(' ')
View FizzBuzz.rb
def fizz_buzz
(1..100).map do |num|
f = num % 3 == 0 ? 'Fizz' : nil
b = num % 5 == 0 ? 'Buzz' : nil
f || b ? "#{f}#{b}" : num
end
end
puts fizz_buzz
View gist:6400721
def leap_year?(year)
if year % 100 == 0
true if year % 400 == 0
else
true if year % 4 == 0
end
end
def minutes_in_year(year)
if leap_year?(year)
@bricejlin
bricejlin / gist:6399841
Created Aug 31, 2013
ruby learning wk 2 c 1
View gist:6399841
def prompt(question)
puts question
answer = gets.chomp
end
You can’t perform that action at this time.