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
// for loop compare with the use of obj to check for duplicate => 400-500ms at 1mil elm | |
function maxNum(x) | |
{ | |
var m = -Infinity, i = 0, n = x.length; | |
for (; i != n; ++i) { | |
if (x[i] > m) { | |
m = x[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
//aaray.sort(with integer compare) | |
//this will generate an array that contains t number of elements | |
var inputArr = []; | |
for (var i=0, t=1000000; i<t; i++) { | |
inputArr.push(Math.round(Math.random()*t)) | |
} | |
console.log(inputArr); | |
var sortFunc = function(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
var array = []; | |
var light = function arrayOfLight(number) { | |
for (i = 0; i < number + 1; i++){ | |
array.push(i); | |
} | |
} | |
light(13); | |
console.log(array); |
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
#Exercise 1 | |
SELECT e.isbn | |
FROM editions AS e | |
INNER JOIN publishers AS p | |
ON e.publisher_id = p.id | |
WHERE name = 'Random House' | |
; | |
#Exercise 2 |
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
require_relative 'contact_database.rb' | |
class Contact | |
attr_accessor :name, :email | |
def initialize(name, email) | |
@name = name | |
@email = email | |
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
require_relative 'contact_database.rb' | |
class Contact | |
attr_accessor :name, :email | |
def initialize(name, email) | |
@name = name | |
@email = email | |
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
require 'active_support/all' | |
@candidates = [ | |
{ | |
id: 5, | |
years_of_experience: 4, | |
github_points: 293, | |
languages: ['C', 'Ruby', 'Python', 'Clojure'], | |
date_applied: 5.days.ago.to_date, | |
age: 26 |
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
# Determine whether a string contains a SIN (Social Insurance Number). | |
# A SIN is 9 digits and we are assuming that they must have dashes in them | |
def has_sin?(string) | |
if /\d{3}-\d{3}-\d{3}/.match(string) | |
return true | |
end | |
end | |
# puts "has_sin? returns true if it has what looks like a SIN" | |
# puts has_sin?("please don't share this: 234-604-142") == true |
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 benchmark | |
start_time = Time.now | |
yield | |
end_time = Time.now | |
run_time = end_time - start_time | |
# Your benchmarking code goes here. | |
end | |
# Be careful, pasting this into IRB will take a long time to print. | |
# It's a loooong string. :) |
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 count_index(input) | |
letters = {} | |
words = input.split(" ") | |
conc_word = nil | |
words.each do |word| | |
if conc_word == nil | |
conc_word = word | |
else | |
conc_word += word | |
end |
NewerOlder