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
| def full_name(first, *rest) | |
| array = [] | |
| rest.map{|x| array << x } | |
| array2 = [] | |
| return error if first == nil | |
| array2 << first | |
| array2.concat(array).join(" ") | |
| end | |
| ### array "names" includes all arguments | |
| def full_name(*names) |
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
| def evaluate_num(val) | |
| return "RED" if val <= 2 | |
| return "BLUE" if val > 3 | |
| end | |
| (1..5).group_by {|x| | |
| evaluate_num(x) | |
| } | |
| #=> {"RED"=>[1, 2], "BLUE"=>[3, 4, 5]} | |
| #marks = {"Ramesh":23, "Vivek":40, "Harsh":88, "Mohammad":60} |
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
| def func_any(hash) | |
| # Check and return if any key object within the hash is of the type Integer | |
| hash.any? {|key, value| key.is_a? Integer} | |
| end | |
| def func_all(hash) | |
| # Check and return if all the values within the hash are Integers and are < 10 | |
| hash.all? {|key, value| value < 10} | |
| end |
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
| def sum_terms(n) | |
| (1..n).reduce(0){|sum, i| sum + i**2 + 1} | |
| end |
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
| def rot13(secret_messages) | |
| secret_messages.map { |x| | |
| x.tr!("A-Za-z", "N-ZA-Mn-za-m") | |
| } | |
| end |
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
| array = [] | |
| sample = %w(a b c d e) | |
| sample.each_with_index { |item, index| array[index] = "#{index}:#{item}" } | |
| p array | |
| => ["0:a","1:b","2:c","3:d","4:e"] |
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
| #You have been provided with a custom object called colors that defines it's own each method. | |
| #You need to iterate over the items and return an Array containing the values. | |
| def iterate_colors(colors) | |
| colors.map{|value| value} | |
| end |
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
| #!/bin/bash | |
| read N | |
| if [ ${N} -gt 5 -o ${N} -lt 1 ]; then | |
| echo "input number must be =< 5 & => 1" | |
| fi | |
| ###design | |
| ## vertical | |
| for((countY=0;countY<${N};countY++)); do | |
| USE_VERTICAL=$((${USE_VERTICAL} + 2 * $((16 / 2 ** ${countY})))) | |
| done |