Skip to content

Instantly share code, notes, and snippets.

View samkahchiin's full-sized avatar
🎯
Focusing

Sam Kah Chiin samkahchiin

🎯
Focusing
View GitHub Profile
# Save this file to your computer so you can run it
# via the command line (Terminal) like so:
# $ ruby deaf_aunty.rb
#
# Your method should wait for user input, which corresponds
# to you saying something to your Aunty.
# You'll probably want to write other methods, but this
# encapsulates the core Aunty logic
def to_roman(num)
# Your code here
roman_hash = { "M" => 1000,
"CM" => 900,
"D" => 500,
"CD" => 400,
"C" => 100,
"XC" => 90,
"L" => 50,
"XL" => 40,
# This is how you define your own custom exception classes
class NoOrangesError < StandardError
end
class OrangeTree
def initialize
@age = 0
@orange_on_tree = []
@height = 0
@samkahchiin
samkahchiin / roman_numeral.js
Created March 27, 2016 09:14
Convert the given number into a roman numeral.
function convert(num) {
var roman_hash = { "M" : 1000,
"CM" : 900,
"D" : 500,
"CD" : 400,
"C" : 100,
"XC" : 90,
"L" : 50,
"XL" : 40,
"X" : 10,
@samkahchiin
samkahchiin / where.js
Last active March 27, 2016 10:00
freecodecamp - where art thou
function where(collection, source) {
var arr = [];
// What's in a name?
var key = Object.keys(source);
for( var i = 0; i < collection.length; i++ ){
var counter = 0;
for (var k = 0; k < key.length; k++){
@samkahchiin
samkahchiin / replace.js
Created March 27, 2016 10:10
freecodecamp : Search and Replace
function myReplace(str, before, after) {
var regex = new RegExp(before);
if(before[0] === before[0].toUpperCase()){
after = after[0].toUpperCase() + after.slice(1) ;
}
return str.replace(regex,after);
}
@samkahchiin
samkahchiin / pig_latin.js
Created March 27, 2016 10:27
freecodecamp : Pig Latin
function translate(str) {
if((/^[aeiou]$/i).test(str[0])){
str = str + "way";
}else{
if((/^[aeiou]$/i).test(str[1])){
str = str.slice(1) + str[0] + "ay";
}else{
str = str.slice(2) + str[0] + str[1] + "ay";
}
@samkahchiin
samkahchiin / dna_pair.js
Created March 27, 2016 10:35
freecodecamp : DNA Pairing
function pair(str) {
var dna_pair = { "A" : "T",
"T" : "A",
"C" : "G",
"G" : "C"};
str = str.split("");
for(var i = 0; i < str.length; i++){
var arr = [str[i]];
@samkahchiin
samkahchiin / missing_letter.js
Created March 27, 2016 11:23
freecodecamp : Missing Letters
function fearNotLetter(str) {
var charCode = String.charCodeAt(str[0]);
for(var i = 1; i < str.length; i++){
charCode++;
if(str[i] != String.fromCharCode(charCode).toLowerCase()){
return String.fromCharCode(charCode);
}
}
}
@samkahchiin
samkahchiin / unite.js
Created March 27, 2016 11:56
freecodecamp : sorted union
function unite(arr1, arr2, arr3) {
var combined = arguments[0];
for(var x = 1; x < arguments.length; x++){
for(var i = 0; i < arguments[x].length; i++){
var counter = 0;
for(var j = 0; j < combined.length; j++){
if(arguments[x][i] != combined[j]){
counter++;
}