Question: Is there a good way to add a certain value to each element in an array in javascript? Essentially, this should be a better way of writing the following:

```
      a = [1,2,3,4];
      for (i = 0; i < a.length; i++) {
          a[i] += 7;
      }

```

Maybe using map (but not necessarily)?

Edit:

Or a more interesting example:

```
      a = [{'x':1},{'x':2},{'x':3},{'x':4}];

      for (i = 0; i < a.length; i++) {
          a[i].x += 7;
      }

```

Answer: 
I recommend using built in function AVMakeRectWithAspectRatio.

```
func AVMakeRectWithAspectRatioInsideRect(_ aspectRatio: CGSize, _ boundingRect: CGRect) -> CGRect

```

**Parameters:**

**aspectRatio:**  

The width and height ratio (aspect ratio) you want to maintain.

**boundingRect:**
 The bounding rectangle you want to fit into.

**Return Value**
Returns a scaled CGRect that maintains the aspect ratio specified by aspectRatio that fits within bounding Rect.

let boundingBox = AVMakeRectWithAspectRatioInsideRect(backgroundImage.size, frame)
**Swift 3.0**

I know its quite late but might help someone in future. Its very simple and inbuilt solution provided by iOS. Just need to: 

`import AVFoundation  

let imageRect = AVMakeRect(aspectRatio: image.size, insideRect: self.imageView.bounds)`