This file contains hidden or 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 Numeric | |
| def factorial() | |
| self < 0 ? raise("You can't take the factorial of a negative number") : factorial_h(1,self) | |
| end | |
| def factorial_h(accum, n) | |
| n <= 1 ? accum : factorial_h(accum * n, n -1 ) | |
| end | |
| end |
This file contains hidden or 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 weather(sym) | |
| {:san_francisco => 60, :chicago => 30, :miami => 70, :los_angeles => 80, :anchorage => 10}[sym] | |
| end |
This file contains hidden or 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 triangle(n1,n2,n3) | |
| n1n2 = n1 == n2 | |
| n2n3 = n2 == n3 | |
| n1n3 = n1 == n3 | |
| if n1 >= n2 + n3 || n2 >= n1 + n3 || n3 >= n1 + n2 | |
| :invalid | |
| elsif n1n2 && n2n3 && n1n3 | |
| :equilateral | |
| elsif n1n2 || n2n3 || n1n3 |
This file contains hidden or 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 title_case(str) | |
| str.split.map{ |el| el.capitalize }.join(" ") | |
| end |
This file contains hidden or 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 sum(ar) | |
| ar.inject(0, :+) | |
| end |
This file contains hidden or 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 one_more(ar) | |
| ar << ar.last | |
| end |
This file contains hidden or 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
| <h3>Numbers</h3> | |
| <h4 class="gray">Addition, Subtraction, Multiplication</h4> | |
| <h4 class="gray" >Division, Integers, And Floats</h4> | |
| <h4 class="gray" >Variables</h4> | |
| <h4 class="gray" >Arithmetic On Variables</h4> | |
| <br /> | |
| <h3>Methods</h3> | |
| <h4 class="gray" >Methods Definition</h4> | |
| <h4 class="gray" >Arguments</h4> | |
| <h4 class="gray" >Method Chaining</h4> |
This file contains hidden or 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 leap_year?(yr) | |
| yr % 4 == 0 && ( yr % 100 != 0 || yr % 400 == 0 ) | |
| end |
This file contains hidden or 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 greeter(first, last) | |
| name = first + last | |
| if %w{ ShereefBishay TonyPhillips AnneSpalding }.include? name | |
| "I love Dev Bootcamp!" | |
| elsif %w{ JesseFarmer RobertFletcher }.include? name | |
| "Will you look at the C source code for this with me?" | |
| else | |
| "Well hello there." | |
| end | |
| end |
This file contains hidden or 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
| module InWords | |
| def in_words() | |
| ones_array = %w{ not_called one two three four five six seven eight nine ten} | |
| tens_array = %w{ not_called not_called twenty thirty forty fifty sixty seventy eighty ninety} | |
| teens_array = [ "" ] + %w{ one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen} | |
| if self == 0 | |
| return "zero" | |
| end |