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
var merge_unique = function(array1, array2){ | |
var len1 = array1.length; | |
var len2 = array2.length; | |
var buff = [] | |
var i = 0, j = 0 | |
while(i != len1 && j != len2){ | |
if(array1[i] < array2[j]) | |
buff.push(array1[i++]); | |
else |
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
function Promise(){ | |
this.callbacks = []; | |
this.value = undefined; | |
} | |
Promise.prototype.success = function(callback){ | |
this.callbacks.push(callback); | |
if(this.value) | |
this.execute_callbacks(); | |
} |
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 is_lower(c) | |
c.ord >= 'a'.ord && c.ord <= 'z'.ord | |
end | |
def is_upper(c) | |
c.ord >= 'A'.ord && c.ord <= 'Z'.ord | |
end | |
def rotx(x, string, encrypt = true) | |
x = encrypt ? x : -x |
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
function Promise(){ | |
this.callbacks = []; | |
this.value = undefined; | |
} | |
Promise.prototype.success = function(callback){ | |
this.callbacks.push(callback); | |
if(this.value) | |
this.execute_callbacks(); | |
} |
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
### ALGORITHM ### | |
# for each index 0 .. last_index | |
#for each index i .. 0 | |
# during each iteration of the inner loop | |
# we store one member of a diagonal from the upper-left half | |
# and the element that reflects it across the line y=x (the middle diagonal) | |
# the member from the upper-left half is at index [i-j][i] | |
# we push this member into the final array at index i |
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
matrix = ('a'..'y').each_slice(5).to_a | |
def all_diagonals(m) | |
len = m[0].length | |
final = Array.new(2*len - 1){[]} | |
0.upto(len-1) do |i| | |
i.downto(0) do |j| | |
final[i] << m[i-j][j] | |
final[2*len-i-2] << m[len-1-j][j+len-i-1] if 2*len-i-2 != len-1 |
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
a = [447, 462, 9, 272, 242, 0, 206, 998, 35, 414] | |
def max(a, i, memo = {}) | |
return 0 if i == 0 | |
return a[i] if i == 1 | |
return memo[i] if memo[i] | |
return memo[i] = [max(a,i-2) + a[i], max(a,i-1)].max | |
end | |
p max(a, 9) |
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> | |
<script type="text/javascript" src="timer.js"></script> | |
</head> | |
<input id="seconds" type="text" value="0"> | |
<div id="countdown"> | |
<span class="days">0 days</span> | |
<span class="hours">0 hours</span> |
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
##################################### P1 | |
def reverse(string) | |
string.length == 0 ? "" : string[-1] + reverse(string[0..-2]) | |
end | |
##################################### P2 | |
def tokenize(url) | |
url.split(/&/).map { |i| i.split(/=/) } |
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 tokenize(url) | |
url.split(/&/).map { |i| i.split(/=/) } | |
end | |
def dict(array_of_pairs) | |
array_of_pairs.inject(Hash.new{[]}) { |hash,pair| hash[pair.first] += [pair.last] ; hash } | |
end | |
def scrub(hash) | |
hash.map { |k,v| hash[k] = v.first if v.length == 1 } |
NewerOlder