We're created a struct and a function that compares sizes of two rectangles:
struct Rectangle {
let width: Int
let height: Int
func isBiggerThan(_ rectangle: Rectangle) -> Bool {
let areaOne = width * height
let areaTwo = rectangle.width * rectangle.height
return areaOne > areaTwo
}
}
let rectangle = Rectangle(width: 10, height: 10)
let otherRectangle = Rectangle(width: 10, height: 20)
rectangle.isBiggerThan(otherRectangle)
otherRectangle.isBiggerThan(rectangle)
My exercise is: Simplify the isBiggerThan method by creating a computed property named area for the rectangle struct and then using the computed property inside the isBiggerThan() method.
Could someone please explain how the previous code works and how to simplify this code by using a computed property