Skip to content

Instantly share code, notes, and snippets.

View euwest's full-sized avatar

Connor Harwood euwest

View GitHub Profile
@euwest
euwest / sum-pairs.js
Created March 21, 2015 04:54
left-most sum pair
var sumPairs = function(integerArray, target) {
var solution;
var findMatch = function(nums) {
var first = nums[0];
var second;
for(var i = 1; i < nums.length; i++) {
second = nums[i];
if(first + second == target) {
solution = [first, second];
var http = require('http');
var urls = process.argv.slice(2);
var results = {};
var printResults = function() {
urls.forEach(function(url) {
console.log(results[url]);
});
};
@euwest
euwest / jquery_example.html
Last active August 29, 2015 13:58 — forked from dbc-challenges/jquery_example.html
Intro to jQuery for Phase 0
<!DOCTYPE html>
<html>
<head>
<title>DOM manipulation with jQuery</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery_example.js"></script>
</head>
<body>
<h1> Hello. Welcome to the jQuery DOM Manipulation Challenge! </h1>
<div class="mascot">
@euwest
euwest / 0.2.1-boggle_class_from_methods.rb
Last active August 29, 2015 13:56 — forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
phase 0 unit 2 week 1boggle class challenge
class BoggleBoard
attr_reader :board
def initialize board
@board = board
end
def create_word(*coords)
coords.map { |coord| @board[coord.first][coord.last]}.join("")
@euwest
euwest / gist:8648524
Created January 27, 2014 13:24
socrates/exercises/Print out a times table
def times_table(rows)
column = 0
rows.times do
column += 1
rows.times do |i|
print "#{((i+1)*column).to_s.center(5)}"
end
print "\n"
end
end
@euwest
euwest / gist:8648179
Created January 27, 2014 13:01
socrates/exercises/Implement the factorial function
def factorial(n)
n > 0 ? (1..n).inject(1) {|sum, x| sum * x} : 1
end
@euwest
euwest / gist:8648101
Created January 27, 2014 12:57
socrates/exercises/Count the numbers in an array between a given range
def count_between(array, lower_bound, upper_bound)
incs = []
array.each do |x|
incs << x if (lower_bound..upper_bound).include?(x)
end
incs.count
end
@euwest
euwest / gist:8647803
Created January 27, 2014 12:37
socrates/exercises/Find the longest string in an array
def longest_string(array)
longest = ''
array.length.times do |i|
longest = array[i] if array[i].length >= longest.length
end
array == [] ? nil : longest
end
@euwest
euwest / gist:8647622
Created January 27, 2014 12:20
socrates/exercises/calculating the array mode
def mode(array)
most = []
freq = 0
num = {}
array.each do |x|
num[x] = 0 if num[x].nil?
num[x] += 1
end