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 LinkedList | |
| def initialize | |
| @head = nil | |
| end | |
| def each | |
| node = @head | |
| while !node.nil? | |
| yield(node.data) |
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
| #You can get the recent articles by saving the data daily | |
| #and look for the differences between the new data and the saved data | |
| #unfortunately, saving all of the data from the NYT API might take up a lot of space | |
| #you will probably need to create an event trigger that takes snapshots of the JSON data sent once a day. | |
| json_data_from_api = articles_from_today | |
| #today_total has each element be an article. The array contains all the articles created up to date. |
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
| var randomNumber = Math.round(Math.random()*10+1); | |
| var userName = prompt("What is your name?"); | |
| var guess = prompt(userName+", please guess a number between 1 and 10:"); | |
| if (guess == randomNumber) { | |
| alert("You're so special, "+userName+", you totally won this game!!! zomg"); | |
| } else { | |
| alert("You suck at life, "+userName+", you can't even guess a number right."); |
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 Minefield | |
| attr_reader :row_count, :column_count, :mine_count, :cleared_cells, :mines | |
| def initialize(row_count, column_count, mine_count) | |
| @column_count = column_count | |
| @row_count = row_count | |
| @mine_count = mine_count | |
| @cleared_cells = [] | |
| @mines = place_mines |
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 'pry' | |
| def schedule_tournament(names) | |
| tournament = [] | |
| round = [] | |
| # n = names.length | |
| round_count = (n-1) | |
| pnames = names.dup |
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 'pry' | |
| def sort_list(arr) | |
| list_array=arr.split(' ') | |
| list_array.map!{|num| num.to_f} | |
| rec_sort_list(list_array, []) | |
| end | |
| def rec_sort_list(list, sorted) |
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 TV | |
| def initialize(size,brand) | |
| @size = size | |
| @brand = brand | |
| end | |
| end | |
| class Channel(network) | |
| @network = network | |
| @channel_number = channel_number |
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 Whiteboard | |
| attr_accessor :contents | |
| def initialize(contents = []) | |
| @contents = contents | |
| end | |
| def erase | |
| @contents = [] | |
| 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
| class Card | |
| def initialize(rank, suit) | |
| @suit = suit | |
| @rank = rank | |
| end | |
| def rank | |
| @rank | |
| 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
| class Car | |
| def initialize(color, owner, cylinders) | |
| @color = color | |
| @owner = owner | |
| @cylinders = cylinders | |
| end | |
| def color | |
| @color | |
| end |
NewerOlder