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
# Place in your project here: .git/hooks/pre-commit | |
# Runs all cops on newly added files | |
# Runs standard cops on files that have been modified | |
#!/usr/bin/env ruby | |
require 'rubocop' | |
def get_files(selector) |
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
const linearRegression = (data, y_attr, x_attr) => { | |
//separate data into x and y sets | |
let y_data = []; | |
let x_data = []; | |
for (let i = 0; i < data.length; i++) { | |
y_data.push(data[i][y_attr]); | |
x_data.push(data[i][x_attr]); |
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
/* mergeSort | |
* | |
* basic idea is as follows: | |
* break an array of integrers into pieces recursively | |
* and merges it back together using its sorted pieces | |
* | |
* this implementation uses "take from the front put in | |
* the back" logic while merging | |
* | |
* find diagram at http://quiz.geeksforgeeks.org/merge-sort/ |
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
/* -- Problem -- | |
* Have the function alphabetShift(str) take the str parameter | |
* being passed and modify it using the following algorithm. | |
* Replace every letter in the string with the letter following it | |
* in the alphabet (ie. c becomes d, z becomes a). Then capitalize | |
* every vowel in this new string (a, e, i, o, u) and finally return | |
* this modified string. | |
*/ | |
/* -- Examples -- |
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
// Palindromes are the same forwards as in reverse | |
// As an example, if the input was “I like racecars that go fast”, | |
// the largest palindrom substring (racecar) | |
// would have the length of 7. | |
var longestPalindrome = function(s){ | |
let biggest = 0; | |
const stringLength = s.length; |
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
"use strict"; | |
var _ = { | |
// Implements: | |
// https://lodash.com/docs#map | |
map: (array, callback) => { | |
var newArray = [] | |
array.forEach(function(item){ | |
newArray.push(callback(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
# -- Setup | |
# - recursive | |
def recursive_fib(x) | |
x < 2 ? x : recursive_fib(x-1) + recursive_fib(x-2) | |
end | |
# - iterative | |
def iterative_fib(num) |
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 LinkedListNode | |
attr_accessor :value, :next_node | |
def initialize(value, next_node=nil) | |
@value = value | |
@next_node = next_node | |
end | |
end | |
def print_list(list_node) |
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
# selecting | |
def choose_best_guess(ary) | |
ary.select{ |v| v <= t }.max | |
end | |
# rejecting | |
def choose_best_guess(ary) | |
ary.reject{ |v| v > t }.max | |
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 choose_best_trip(t, k, ls) | |
ls.combination(k).to_a.map{|a| a.reduce(:+)}.select{ |v| v <= t }.max | |
end | |
# example: ts = [50, 55, 56, 57, 58] choose_best_trip(163, 3, ts) -> 163 | |
# Tests | |
Test.describe("choose_best_sum") do | |
Test.it("Basic Tests") do |