Skip to content

Instantly share code, notes, and snippets.

// Write a function charFreq() that takes a string and builds a frequency listing of the characters contained in it.
// Represent the frequency listing as a Javascript object.
// Try it with something like charFreq("abbabcbdbabdbdbabababcbcbab").
// I got a lot help from stack on this one. I had no idea how to make a object from a string.
// and in doing research for that I found a solution to something similar to this. But I do understand
// how every line of code works and why!
function charFreq(source) {
var frequency = {};
// Represent a small bilingual lexicon as a Javascript object in the following fashion {"merry":"god", "christmas":"jul", "and":"och", "happy":gott", "new":"nytt", "year":"år"} and use it to translate your Christmas cards from English into Swedish.
var greetings = {
"merry": "god",
"christmas": "jul",
"and": "och",
"happy": "gott",
"new": "nytt",
"year": "ar"
};
@kunalbhatt
kunalbhatt / card.rb
Created October 25, 2012 21:58 — forked from dbc-challenges/card.rb
FlashCardinator
# Your code here
@kunalbhatt
kunalbhatt / gist:3928770
Created October 21, 2012 22:31
Minitest with Expectations
require 'minitest/autorun'
require 'minitest/spec'
def switcharoo(string, switch_point, second_switch_point = nil)
first = string.slice(0...switch_point)
second = string.slice(switch_point..-1)
second + first
end
describe "switcharoo" do
@kunalbhatt
kunalbhatt / object_privacy.rb
Created October 12, 2012 00:23
Object Privacy
# Def initialize
class BankAccount
attr_reader :customer_name, :type, :acct_number
def initialize(customer_name, type, acct_number)
@customer_name = customer_name
@type = type
@acct_number = acct_number
end
end
@kunalbhatt
kunalbhatt / Pig_latin.rb
Created October 3, 2012 21:03
Pig_latin tumblr
# Solution for Challenge: Implement from Pseudocode. Started 2012-10-02T04:28:05+00:00
#Iteration One
def pig_latin
vowels = [ 'a', 'e', 'i', 'o', 'u' ]
puts "Please enter word to be translated:"
word = gets.chomp
split_word = word.chars.to_a
if vowels.include?(split_word[0])
psuedo_vowel = word
@kunalbhatt
kunalbhatt / gist:3816456
Created October 2, 2012 05:46
Primes Review
def primes(num)
primes = [ ]
(2..num).each do |divider|
until num % divider != 0
if num % divider == 0
primes << divider
num = num/divider
end
end
end