####Install…
This file contains 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
/** | |
* The first commented line is your dabblet’s title | |
*/ | |
background: #f06; | |
background: linear-gradient(45deg, #f06, yellow); | |
min-height: 100%; |
This file contains 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
#total sum of array .each vs. .length.times | |
#using .length.times | |
def total(array) | |
sum = 0 | |
#The length method returns the size of the array. | |
#Here, adding .times iterates the following block length times... | |
array.length.times do |x| | |
#...since the use of .times passes the parameter, x, 0 through (length -1), | |
#the block needs to get the value the array elements via index. |
This file contains 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
# PSEUDOCODE | |
# INPUT: an array of numbers | |
# OUPUT: sum of all numbers in array | |
# STEPS: start with a total of zero | |
# iterate over each element in the array | |
# for each element, add its value to the total | |
# return the total after there are no more elements | |
# INITIAL CODE: |
This file contains 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
# PSEUDOCODE | |
# INPUT: array of grades | |
# OUPUT: a string representation of the letter grade that corresponds with | |
# the average score of the array of grades | |
# STEPS: Compute the average value of the values in teh input array | |
# divide the average by the length of input array => computes average score | |
# define letter grade distribution | |
# convert the average score to its corresponding letter grade | |
# return letter grade, as string |
This file contains 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
# CALCULATE THE MEDIAN OF AN ARRAY OF NUMBERS | |
# PSEUDOCODE | |
# INPUT: array of numbers | |
# OUPUT: the median number of the elements of the input array | |
# STEPS: sort the array | |
# determine if the array has one or two middle values by checking | |
# if the length is even or odd | |
# if there is an odd length, return the value of the middle element | |
# otherwise return the average of the two middle elements' values |
This file contains 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
# CALCULATE THE MEDIAN OF AN ARRAY OF NUMBERS | |
# PSEUDOCODE | |
# INPUT: array object takes a non-negative integer minimum array size, | |
# optional value to pad which defaults to nil | |
# OUPUT: array object (#pad! returnning the same object while #pad | |
# will return a copy) which is padded conditional on its existing | |
# attributes and the passed parameters | |
# STEPS: for #pad! [#pad will do the same, but make a copy prior to executing | |
# anything with the potential to modify it] if the array is smaller than the |
This file contains 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
# Solution for Challenge: Review Others, Refactor Yours: Pad an Array. Started 2014-01-13T02:14:42+00:00 | |
# FIRST ATTEMPT | |
## ORIGIAL CODE: | |
class Array | |
def pad!(min_size, value = nil) | |
if self.length < min_size | |
(min_size - self.length).times do | |
self << value |
This file contains 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
# PSEUDOCODE | |
# INPUT: array object takes a non-negative integer minimum array size, | |
# optional value to pad which defaults to nil | |
# OUPUT: array object (#pad! returnning the same object while #pad | |
# will return a copy) which is padded conditional on its existing | |
# attributes and the passed parameters | |
# STEPS: for #pad! [#pad will do the same, but make a copy prior to executing | |
# anything with the potential to modify it] if the array is smaller than the |
OlderNewer