- Keep a separate desk exclusively for Turing work
- Only ever use my Turing laptop for Turing work
- Ensure that the work desk never gains an item of clutter
- The only item that may be placed atop the school desk is an item that is being used for school
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
by David Stavis | |
Please leave feedback. |
Write a method mode which takes an Array of numbers as its input and returns an Array of the most frequent values. | |
If there's only one most-frequent value, it returns a single-element Array. | |
For example, | |
mode([1,2,3,3]) # => [3] | |
mode([4.5, 0, 0]) # => [0] | |
mode([1.5, -1, 1, 1.5]) # => [1.5] | |
mode([1,1,2,2]) # => [1,2] |
def median(array) | |
array.sort! | |
#if total number of items in the array is odd, | |
if array.length % 3 == 0 | |
#Figure out the index of the middle item. Which is one greater than half the length rounded down. | |
middle_index = array.length / 2 + 1 | |
middle_index = middle_index.to_int | |
#return the item at that index | |
median = array[middle_index] |
#Write a method valid_triangle? which takes as its input three non-negative numbers. | |
def valid_triangle?(a, b, c) | |
#if the three numbers could form the side lengths of a triangle | |
if a**2 + b**2 == c**2 | |
#It should return true | |
return true | |
#and false otherwise. | |
else | |
return false |
# longest_string is a method that takes an array of strings as its input | |
# and returns the longest string | |
# | |
# +array+ is an array of strings | |
# longest_string(array) should return the longest string in +array+ | |
# | |
# If +array+ is empty the method should return nil | |
def longest_string(array) | |
return nil if array.empty? | |
Write a factorial method which takes as its input a non-negative integer and calculates the factorial of that number. | |
The factorial of a number is the product of all integers from 1 up to that number. For example: | |
factorial(5) == 5 * 4 * 3 * 2 * 1 == 120 | |
The factorial of 0 is defined to be 1. | |
------------CODE------------- | |
def super_fizzbuzz(array) | |
#It should return a "fizzbuzzed" Array, i.e., the array is identical to the input with the following substitutions: | |
array.each do |number| | |
#Multiples of 3 should be replaced with the string "Fizz" | |
#Multiples of 5 should be replaced with the string "Buzz" | |
#Multiples of 15 should be replaced with the string "FizzBuzz" | |
if number % 3 == 0 |
class BoggleBoard | |
def initialize(board) | |
@board = board | |
end | |
# method that maps through each | |
def create_word(*coords) | |
coords.map { |coord| @board[coord.first][coord.last] }.join("") #@board is a 2D array | |
end |