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 Person | |
| attr_reader :name | |
| attr_writer :name | |
| def initialize(name) | |
| @name = name | |
| end | |
| # def name |
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
| require 'active_support/all' | |
| @candidates = [ | |
| { | |
| id: 5, | |
| years_of_experience: 4, | |
| github_points: 293, | |
| languages: ['C', 'Ruby', 'Python', 'Clojure'], | |
| date_applied: 5.days.ago.to_date, | |
| age: 26 |
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 benchmark | |
| benchmark_result = yield | |
| start_time = Time.now | |
| benchmark_result.reverse | |
| end_time = Time.now | |
| running_time = end_time - start_time | |
| end | |
| # Be careful, pasting this into IRB will take a long time to print. | |
| # It's a loooong string. :) |
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 Library { | |
| constructor(libraryName, creator){ | |
| this.libraryName = libraryName; | |
| this.creator = creator; | |
| this.playlists = []; | |
| } | |
| addPlaylist(playlist){ | |
| this.playlists.push(playlist) | |
| } |
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
| <!DOCTYPE HTML> | |
| <html> | |
| <head> | |
| <style> | |
| body { | |
| margin: 0px; | |
| padding: 0px; | |
| } | |
| </style> | |
| </head> |
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
| function maxProfit(prices){ | |
| var maxProfit = prices[1] - prices[0]; | |
| var minPrice = prices[0]; | |
| for(var i = 1; i < prices.length; i++) | |
| { | |
| if (prices[i] - minPrice > maxProfit) | |
| maxProfit = prices[i] - minPrice; | |
| if (prices[i] < minPrice) | |
| minPrice = prices[i]; | |
| } |
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
| function maxProfit(prices){ | |
| var maxProfit = prices[1] - prices[0]; | |
| var minPrice = prices[0]; | |
| for(var i = 1; i < prices.length; i++) | |
| { | |
| if (prices[i] - minPrice > maxProfit) | |
| maxProfit = prices[i] - minPrice; | |
| if (prices[i] < minPrice) | |
| minPrice = prices[i]; | |
| } |
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
| function maxProfit(prices){ | |
| var maxProfit = 0; | |
| for(var i = 0; i < prices.length; i++){ | |
| for(var j = 0; j < prices.length; j++){ | |
| if(i > j){ | |
| var possibleProfit = prices[i] - prices[j]; | |
| if (possibleProfit > maxProfit){ | |
| maxProfit = possibleProfit; | |
| } | |
| } |