This file contains hidden or 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
| qas = %w[holden darius curt ryan1 ryan2 ryan3] | |
| puts qas.delete(qas.sample) until qas.empty? |
This file contains hidden or 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
| *********** | |
| **PROBLEM** | |
| *********** | |
| **INPUT** | |
| Upon form submission an array like the following is provided as a value to a key in Sinatra's params hash | |
| [{"job_id"=>"43", "new_order"=>""}, | |
| {"job_id"=>"44", "new_order"=>""}, | |
| {"job_id"=>"46", "new_order"=>""}, | |
| {"job_id"=>"47", "new_order"=>""}, |
This file contains hidden or 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
| function railFenceCipher(operation, string, height = 3) { | |
| function performOperation(operation, string, height, lines) { | |
| let results = ''; // only for decrypt | |
| let currentLine = 0; | |
| let moveUp = true; | |
| let moveDown = false; | |
| for (let i = 0; i < lines[0].length; i += 1) { | |
| if (operation === 'encrypt') { | |
| lines[currentLine].splice(i, 1, string[i]); |
This file contains hidden or 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
| function railFenceCipher(operation, string, height = 3) { | |
| function encrypt(string, height, fence) { | |
| let currentRail = 0; | |
| let moveUp = true; | |
| let moveDown = false; | |
| for (let i = 0; i < fence[0].length; i += 1) { | |
| fence[currentRail].splice(i, 1, string[i]); | |
| if ((moveUp && currentRail + 1 > height - 1) || |
This file contains hidden or 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
| function longestSentence(text) { | |
| let biggestSentence = { sentence: null, wordCount: 0, }; | |
| while (text.length > 0) { | |
| sentence = text.match(/^[\w\d\s,-]+\b([.!?]\s*)/i)[0]; | |
| text = text.replace(sentence, ''); | |
| sentence = sentence.trim(); | |
| let wordCount = sentence.split(' ').length; | |
| if (biggestSentence.wordCount < wordCount) { |
This file contains hidden or 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
| var studentScores = { | |
| student1: { | |
| id: 123456789, | |
| scores: { | |
| exams: [90, 95, 100, 80], | |
| exercises: [20, 15, 10, 19, 15], | |
| }, | |
| }, | |
| student2: { | |
| id: 123456799, |
This file contains hidden or 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 Hex | |
| HEX = { '1' => 1, '2' => 2, '3' => 3, | |
| '4' => 4, '5' => 5, '6' => 6, | |
| '7' => 7, '8' => 8, '9' => 9, | |
| 'a' => 10, 'b' => 11, 'c' => 12, | |
| 'd' => 13, 'e' => 14, 'f' => 15 } | |
| attr_reader :string | |
| def initialize(input) |
This file contains hidden or 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 Trinary | |
| attr_reader :number | |
| def initialize(value) | |
| @number = value | |
| end | |
| def to_decimal | |
| return 0 if number.match(/[^0-2]/) | |
| converted_num = 0 | |
| number.split('').reverse.each_with_index do |num, index| | |
| converted_num += num.to_i * 3 ** index |
This file contains hidden or 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 School | |
| attr_accessor :grades | |
| def initialize | |
| @grades = {} | |
| end | |
| def to_h | |
| grades.map { |grade, name| grades[grade] = name.sort } | |
| grades.sort.to_h |
This file contains hidden or 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 CircularBuffer | |
| attr_accessor :buffer, :read_index, :write_index | |
| def initialize(length) | |
| @buffer = Array.new(length) | |
| @read_index = 0 | |
| @write_index = 0 | |
| end | |
| def read |
NewerOlder