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
class LinkedListNode | |
attr_accessor :value, :next_node | |
def initialize(value, next_node=nil) | |
@value = value | |
@next_node = next_node | |
end | |
end |
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
class BinaryTree | |
attr_accessor :payload, :left, :right | |
def initialize(payload, left, right) | |
@payload = payload | |
@left = left | |
@right = right | |
end | |
def self.build_tree(array) |
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
class Tree | |
attr_accessor :payload, :children | |
def initialize(payload, children) | |
@payload = payload | |
@children = children | |
end | |
# depth_first returns nil if 11 isn't in the tree | |
def search_node(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
// Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present. | |
function spinWords(string){ | |
return string.split(' ').map(function(word){ | |
if (word.length >= 5) { | |
return word.split('').reverse().join(''); | |
} else { | |
return word; | |
} | |
}).join(' '); |
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
// Write a function toWeirdCase (weirdcase in Ruby) that accepts a string, and returns the same string with all even indexed characters in each word upper cased, and all odd indexed characters in each word lower cased. The indexing just explained is zero based, so the zero-ith index is even, therefore that character should be upper cased. | |
// The passed in string will only consist of alphabetical characters and spaces(' '). Spaces will only be present if there are multiple words. Words will be separated by a single space(' '). | |
function toWeirdCase(string){ | |
return string.split(' ').map(function(word){ | |
return word.split('').map(function(letter, index){ | |
if (index % 2 === 0) { | |
return letter.toUpperCase(); | |
} else if (index % 2 != 0) { |
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
// write a function that creates a black and white chess board. | |
function mineColor(line, number) { | |
if ((line === 'a' || line === 'c' || line === 'e' || line === 'g') && number % 2 == 0) { | |
return 'white'; | |
} else if ((line === 'b' || line === 'd' || line === 'f' || line === 'h') && number % 2 != 0) { | |
return 'white'; | |
} else { | |
return 'black'; | |
} |
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
"use strict"; | |
var _ = { | |
join: (array, separator = ",") => { | |
var str = ""; | |
for (var i = 0; i < array.length; i++) { | |
str += separator + array[i]; | |
} | |
return str.substring(2); | |
} |
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
# n → n/2 (n is even) | |
# n → 3n + 1 (n is odd) | |
# Write a method to determine a number's collatz sequence. | |
# Find the number (1 to 1,000,000) with the longest sequence. | |
# collatz method defined below with (n) as an argument. | |
def collatz(n) |
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
module Luhn | |
def self.is_valid?(number) | |
# ---------------------------------------------------- | |
# | |
# line 17 - take the number, convert it to a string | |
# and reverse it. '.chars' splits it by digit, then |
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
class Bike | |
attr_accessor :brand, :color | |
def initialize(brand, color) | |
@brand = brand | |
@color = color | |
end | |
end |