I completed “Software Engineering Foundations” on June 2nd, which meant I got to start the actual curriculum on June 3rd. The foundations course is ~100 hours of required work for all students. It covered a ton of stuff:
Foundations finishes up with some recap challenges that put everything I learned together. Here are a few exercises I had to solve along with my solution.
Write a method, all_vowel_pairs, that takes in an array of words and returns all pairs of words that contain every vowel. Vowels are the letters a, e, i, o, u. A pair should have its two words in the same order as the original array.
def all_vowel_pairs(words)
pairs = []
vowels = ["a", "e", "i", "o", "u"]
words.each_with_index do |word_1, idx_1|
words.each_with_index do |word_2, idx_2|
pair = word_1 + " " + word_2
pairs << pair if idx_2 > idx_1 && vowels.all? { |vowel| pair.include?(vowel) }
end
end
pairs
end
Write a method, String#substrings, that takes in an optional length argument. The method should return an array of the substrings that have the given length. If no length is given, return all substrings.
def substrings(length = nil)
subs = []
(0...self.length).each do |start_idx|
(start_idx...self.length).each do |end_idx|
sub = self[start_idx..end_idx]
subs << sub
end
end
if length.nil?
subs
else
subs.select { |sub| sub.length == length }
end
end
Write a method, most_frequent_bigram, that takes in a string and returns the two adjacent letters that appear the most in the string.
def most_frequent_bigram(str)
bigrams = Hash.new(0)
(0...str.length - 1).each do |i|
bigram = str[i..i + 1]
bigrams[bigram] += 1
end
sorted = bigrams.sort_by { |k, v| v }
sorted.last[0]
end
After completing Foundations, I jumped right into the Ruby section, which is really just “Learn computer science via Ruby”.
I was instantly hit with a pretty tough problem:
a = [ 4, 5, 6 ]
b = [ 7, 8, 9 ]
p [1, 2, 3].my_zip(a, b) # => [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
p a.my_zip([1,2], [8]) # => [[4, 1, 8], [5, 2, nil], [6, nil, nil]]
[1, 2].my_zip(a, b) # => [[1, 4, 7], [2, 5, 8]]
c = [10, 11, 12]
d = [13, 14, 15]
[1, 2].my_zip(a, b, c, d) # => [[1, 4, 7, 10, 13], [2, 5, 8, 11, 14]]
Staring at the problem for 2 hours only made it harder, but I eventually got there.
Also.. I completed some interesting projects:
I also updated the README for my App Academy repo with an overview of what I’m learning & working on.
Speaking of GitHub.. here’s the current streak:
Current projects I’m working on are a card matching memory game and a Sudoku checker.