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
| source 'https://rubygems.org' | |
| # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' | |
| gem 'rails', '4.1.6' | |
| # Use sqlite3 as the database for Active Record | |
| gem 'sqlite3' | |
| # Use SCSS for stylesheets | |
| gem 'sass-rails', '~> 4.0.3' | |
| # Use Uglifier as compressor for JavaScript assets |
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 opposite(n) | |
| n * -1 | |
| 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 spinWords(string) | |
| string.split.map! {|s| s.length >= 5 ? s.reverse : s}.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 likes(names) | |
| case names.size | |
| when 0 then "no one likes this" | |
| when 1 then "#{names[0]} likes this" | |
| when 2 then "#{names[0]} and #{names[1]} like this" | |
| when 3 then "#{names[0]}, #{names[1]} and #{names[2]} like this" | |
| else "#{names[0]}, #{names[1]} and #{names.length - 2} others like this" | |
| 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 array_diff(a, b) | |
| a.delete_if {|a| b.include?(a)} | |
| 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 count_bits(n) | |
| n.to_s(2).scan("1").count | |
| 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 even_or_odd(number): | |
| return "Odd" if number % 2 != 0 else "Even" |
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 number_to_string(num): | |
| return str(num) |
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
| ######### Refactored ######### | |
| def persistence(n): | |
| if n < 10: return 0 | |
| multiplier = 1 | |
| while(n > 0): | |
| multiplier = (n % 10) * multiplier | |
| n = n // 10 |
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 remove_char(s): | |
| return s[1:-1] |
OlderNewer