Skip to content

Instantly share code, notes, and snippets.

@MrBean83
MrBean83 / zoo.js
Created October 17, 2013 16:33 — forked from dbc-challenges/zoo.js
Phs2_PrAss_Pt. 4 OOJS: Tending the Zoo
//------------------------------------------------------------------------------------------------------------------
// YOUR CODE: Create your Zoo "object literal" and Animal "constructor" and "prototypes" here.
//------------------------------------------------------------------------------------------------------------------
function Animal(name, number_of_legs) {
this.name = name;
this.number_of_legs = number_of_legs;
}
Animal.prototype.identify = function(){
@MrBean83
MrBean83 / index.html
Created October 17, 2013 15:52 — forked from dbc-challenges/index.html
DBC Phase 2 Practice Assessment Part 3
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.jsdelivr.net/normalize/2.1.0/normalize.css">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Lato:100,900">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.0.2/css/font-awesome.min.css">
</head>
class RomanNumerals
def initialize
self.re_pop
end
def converter(test_number, discard = 0, key = @roman_numbers.keys.first)
return "" if test_number == 0
(@roman_numbers[key] * (test_number / key)) +
converter(test_number % key, @roman_numbers.delete(key))
end

Implementing a Reverse Polish notation calculator in Ruby

A couple weeks ago I had a go at implementing an RPN calculator in Ruby. I knew I wanted the calculator to function by popping operands out of an array populated with the values of the input expression, operating upon the operands with the appropriate operator, and pushing the result back into the stack of operands.

I was able to implement this in version 1, but it took forever and the resulting code was not very beautiful. Why?

  • I started coding before I had a thorough understanding of RPN

    Wait, 20 10 5 4 + * - is what now?

@MrBean83
MrBean83 / get_grade
Last active December 20, 2015 01:09
def get_grade(grade)
average = grade.to_i
case average
when 90..100
"A"
when 80...90
"B"
when 70...80
"C"