string = "{key:[[value_1, value_2],[value_3, value4]], 5:10:00AM]}"
h = {"key" => [["value_1", "value_2"],["value_3", "value4"]], 5=>"10:00AM"}Please note that the brackets are unbalanced on purpose.
===
| # She has asked you to create a method print_puzzle that prints the row of dashes for a required, single argument, word. The number of dashes or spaces should equal the amount of characters in the word. print_puzzle can also optionally take a list of characters as a second argument that represents the list of guessed letters. | |
| # Given print_puzzle is called with the word "perimeter", your method should output: _ _ _ _ _ _ _ _ _ | |
| # Given print_puzzle is called with the word "triangle" and the list of characters guessed: t,s,g, your method should output: t _ _ _ _ g _ _ | |
| def print_puzzle(word, guessed_letters = []) | |
| word.chars.map {|char| guessed_letters.include?(char) ? " #{char}" : " _"}.join | |
| end | |
| gem 'minitest' | |
| require 'minitest/autorun' |
| # today's code kata: Write a function called word_count, that takes a sentence as a string as input, and returns the frequency of each word in that sentence, as a hash whose key is the word, and whose count is the number of times that word appears in that sentence. | |
| # 1) ignore case, 2) ignore any non word characters | |
| # Here is the paragraph: | |
| # The quick brown fox jumped over the moon. This mammal did not jump over the sun; it jumped over the moon. And it was quick about it. | |
| # let's use the whole paragraph | |
| def word_count(paragraph) | |
| paragraph.split(/\W+/).map(&:downcase).each_with_object(Hash.new(0)) {|w, hsh| hsh[w] += 1 } | |
| end |
| # Today's kata: | |
| # Given a 3 or 4 digit number with distinct digits, return a sorted array of all the unique numbers that can be formed with those digits. | |
| # ie, given 123, return [123, 132, 213, 231, 312, 321] | |
| def same_digit_numbers(initial_num) | |
| initial_num.to_s.split('').permutation.map {|e| e.join.to_i }.uniq.sort | |
| end | |
| def same_digit_numbers(initial_num) | |
| num_string = initial_num.to_s |
| class Clock | |
| def self.at(hours=0, minutes=0) | |
| new(hours, minutes) | |
| end | |
| def initialize(hours=0, minutes=0) | |
| array = minutes.divmod 60 | |
| @minutes = array[1] | |
| @hours = array[0] + hours |
| result_hash = Hash.new([0, ""]) | |
| File.read("path/to/file").each_line do |line| # something like that | |
| line.each do |column_name, value| # a line is not an hash or nested array, but could possibly convert somehow | |
| if result_hash[column_name][0] < value.length | |
| result_hash[column_name][0] = value.length | |
| result_hash[column_name][1] = line[factual_id] | |
| end | |
| end | |
| end |
| class Sample | |
| def initialize(hsh) | |
| @hsh = hsh | |
| end | |
| def method_missing(method) | |
| key = @hsh.has_key?(method) ? method : method.to_s | |
| @hsh[key] | |
| end |
| # Please answer in either | |
| # Ruby, | |
| # Perl, | |
| # PHP, | |
| # Python or | |
| # Java HTMLCONTROL Forms.HTML:Hidden.1 | |
| # 1. Convert this string | |
| # string = "{key:[[value_1, value_2],[value_3, value4]], 5:10:00AM]}" | |
| # to this hash: |
| 0 info it worked if it ends with ok | |
| 1 verbose cli [ '/Users/ugp/.nvm/versions/node/v4.1.1/bin/node', | |
| 1 verbose cli '/Users/ugp/.nvm/versions/node/v4.1.1/bin/npm', | |
| 1 verbose cli 'install', | |
| 1 verbose cli 'contextify' ] | |
| 2 info using [email protected] | |
| 3 info using [email protected] | |
| 4 silly loadCurrentTree Starting | |
| 5 silly install loadCurrentTree | |
| 6 silly install readLocalPackageData |
| 0 info it worked if it ends with ok | |
| 1 verbose cli [ '/usr/local/Cellar/node/4.1.1/bin/node', | |
| 1 verbose cli '/usr/local/bin/npm', | |
| 1 verbose cli 'install', | |
| 1 verbose cli 'jsdom' ] | |
| 2 info using [email protected] | |
| 3 info using [email protected] | |
| 4 verbose install initial load of /Users/ugp/code/reactjs_koans/package.json | |
| 5 verbose installManyTop reading scoped package data from /Users/ugp/code/reactjs_koans/node_modules/babel/package.json | |
| 6 verbose installManyTop reading scoped package data from /Users/ugp/code/reactjs_koans/node_modules/babel-core/package.json |