Procs and Lambdas • Exercise 2/4

Lambda vs Proc

00:00
0
25 points

Instructions

Create two functions that demonstrate the key difference between
procs and lambdas: argument checking.

  1. strict_add - uses a lambda (checks argument count)
  2. lenient_add - uses a proc (ignores extra arguments)

Lambdas are created with:
```ruby
->(a, b) { a + b }

or

lambda { |a, b| a + b }
```

Both should add two numbers, but:
- Lambda raises ArgumentError if wrong number of args
- Proc ignores extra args or uses nil for missing

Your Code

Results

Click "Run Tests" to see results