Silver Challenge ch. 12

My solution:

func siftBeans(fromGroceryList list: [String]) -> (beans: [String], otherGroceries: [String]) {
  var beans = [String]()
  var otherGroceries = [String]()
  
  for product in list {
    if product.hasSuffix("beans") {
      beans.append(product)
    } else {
      otherGroceries.append(product)
    }
  }
  
  return (beans, otherGroceries)
}

let result2 = siftBeans(fromGroceryList: ["green beans",
                                         "milk",
                                         "black beans",
                                         "pinto beans",
                                         "apples"])


result2.beans == ["green beans", "black beans", "pinto beans"]
result2.otherGroceries == ["milk", "apples"]