Complete the code to create a lambda that adds 5 to its input.
add_five = ->(x) { x [1] 5 }The lambda adds 5 to the input using the + operator.
Complete the code to call the lambda with argument 10.
result = add_five.[1](10)
In Ruby, lambdas are called using the call method.
Fix the error in the lambda creation syntax.
my_lambda = lambda [1] |x| x * 2 }
The correct syntax for lambda creation uses curly braces {} around the block.
Fill both blanks to create a lambda that checks if a number is even.
is_even = ->(n) { n [1] 2 [2] 0 }The lambda uses the modulo operator % to get the remainder and checks if it equals 0 with ==.
Fill both blanks to create a lambda that returns the uppercase version of a string if its length is greater than 3.
transform = ->(s) { s.length [1] 3 ? s.[2] : s }The lambda checks if the string length is greater than 3 using >. If true, it returns the uppercase string with upcase, otherwise returns the original string.