Always Sorted Object Exercise in Ruby
In this guide you will learn how to assign a position of 1 for the first object added to an Array.
Guide Tasks
  • Read Tutorial
  • Complete the Exercise

Summary

Build out a method that will describe a sorted object.

Exercise Description

"Define a method that will describe a sorted object and assign it a position of 1 for the first object added to the array."

Example Data

'array_of_objects = []

    expect(
      position_enforcer(
        array_of_objects,
        { name: 'Robert Shun' }
      )
    ).to eq(
      [
        { name: 'Robert Shun', position: 1 }
      ]
    )'

Real World Usage

The always set of sorted objects is a program that ensures that a collection is always sorted.

Test Cases

Code File