diff --git a/max_by_spec.rb b/max_by_spec.rb new file mode 100644 index 0000000..707a2fd --- /dev/null +++ b/max_by_spec.rb @@ -0,0 +1,20 @@ + +describe 'max_by' do + + sweet_stuff = ['cheesecake', 'lemon cake', 'almond tarte', 'blondies'] + + it 'returns an Enumerator when no block is given' do + expect(sweet_stuff.max_by).to be_an Enumerator + end + + it 'returns the maximum value from the given block' do + expect(sweet_stuff.max_by { |nom| nom }).to eq 'lemon cake' + expect(sweet_stuff.max_by { |nom| nom.length }).to eq 'almond tarte' + end + + it 'takes an optional argument that determines how many values are returned ' do + # expect(sweet_stuff.max_by(2) { |nom| nom }).to eq ['lemon cake', 'cheesecake'] + expect(sweet_stuff.sort.reverse.first(2)).to eq ['lemon cake', 'cheesecake'] + end + +end