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
# 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
def mode(array) | |
array_of_modes = [] | |
#NOTE: | |
#Hash.new(0) differs from defining an empty hash by {} in that: | |
# 1. Hash.new(0) defines an empty hash with a default value of 0 for new keys with undefined values. | |
# 2. {} defines an empty hash that will default to nil for new keys with undefined values. | |
#Here, executing the block on nil will result in NoMethodError as + is undefined for nil, so must Hash.new(0) | |
##############CREATE OUR FREQUENCIES HASH######### |
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: a string | |
# OUPUT & PSEUDOCODE | |
# Contains SSN => OUTPUT: Return boolean true/false | |
# Test string for chars in SSN format | |
# Return SSN => OUTPUT: Return SSN extracted from input, as string | |
# Call Contains SSN method-test if a SSN in string | |
# If contains SSN, extract and return. |
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: a positive integer number formatted without commas | |
# OUPUT: the input number formatted with commas as a string | |
# [refactored solution] | |
# Convert the input number to string | |
# Reverse the string | |
# put a comma after each complete group of 3 characters | |
# reverse and return the 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
#######################################PSEUDOCODE################################### | |
# INPUT: a positive integer | |
# OUPUT: boolean true/false if it is a fibonacci number | |
# generate fib numbers less than or equal to input | |
# test whether input one of the generated fib numbers | |
# return boolean true if is fib number | |
# return boolean false if not a fib number |
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
########################IDENTIFY WHAT EACH LINE OF CODE IS DOING#################### | |
def north_korean_cipher(coded_message) | |
input = coded_message.downcase.split("") #any uppercase chars to lowercase; | |
#splits the string at each char and | |
#returns an array of chars. | |
decoded_sentence = [] #creates empty array to push our deciphered message chars into | |
cipher = {"e" => "a", #deciphers the alphabetical chars into NK key => EN value | |
"f" => "b", | |
"g" => "c", |
OlderNewer