Tuesday, 5 July 2016

Map

Difficulty:
Elementary

Tags:
enumerables

Instructions:
How would you create an array that contains the squares of all elements in a range?

Problem and Solution:

# Solution to 'Map' on rubeque.com
# by jakthegr8
# http://www.rubeque.com/problems/map
assert_equal [1, 4, 9, 16], (1..4).map { |ele| ele * ele }
view raw mapping.rb hosted with ❤ by GitHub

Monday, 4 July 2016

Hello World

Difficulty:
Elementary

Tags:
strings

Instructions:
Use native String#method

Problem and Solution:

# Solution to 'Hello World' on rubeque.com
# by jakthegr8
# http://www.rubeque.com/problems/hello-world
assert_equal 'HELLO WORLD', 'hello world'.upcase
view raw upcase.rb hosted with ❤ by GitHub

String Reverse

Difficulty:
Elementary

Tags:
strings

Instructions:
What happens when you apply reverse? Hint: don't forget to quote your strings!.

Problem and Solution:

# Solution to 'Reverse' on rubeque.com
# by jakthegr8
# http://www.rubeque.com/problems/reverse
assert_equal 'nocab yknuhc'.reverse, 'nocab yknuhc'.reverse

Maximum

Difficulty:
Elementary

Tags:
numbers

Instructions:
Find the max in a given set of numbers

Problem and Solution:

# Solution to 'Maximum' on rubeque.com
# by jakthegr8
# http://www.rubeque.com/problems/maximum
def maximum(arr)
max = 0
arr.each{|ele| max = ele if ele > max}
max
end
assert_equal maximum([2, 42, 22, 02]), 42
assert_equal maximum([-2, 0, 33, 304, 2, -2]), 304
assert_equal maximum([1]), 1
view raw maximum.rb hosted with ❤ by GitHub