Question: I am already using Prisma as an ORM for a Postgres DB. I need to run a simple raw query on a SQL Server DB. I do not need to use any of the ORM features like the Prisma schema, migrations, etc. Is it possible to do with Prisma? I am trying to minimize dependencies.

Answer: 
Your code can give a simple good/bad response as follows:

```
let wordOne = "battle"
let wordTwo = "table"

var letters = wordOne
var good = true
for letter in wordTwo {
  if letters.contains(letter) {
    let idx = letters.firstIndex(of:letter)
    letters.remove(at: idx!)
  } else {
    good = false
    break
  }
}
print(good ? "Good" : "Bad")

```

There's no need to sort the letters of each word. That doesn't make this approach any more efficient. I add the `var letters` just so the value can be modified as the loop runs.

---

Here's an alternate approach using `NSCountedSet`. This isn't a pure `Swift` class but is provided by Foundation.

```
let wordOne = "battle"
let wordTwo = "table"

let set1 = NSCountedSet(array: Array(wordOne))
let set2 = NSCountedSet(array: Array(wordTwo))
let extra = set2.filter { set2.count(for: $0) > set1.count(for: $0) }
print(extra.isEmpty ? "Good" : "Bad")

```

`NSCountedSet` is a subclass of `Set` (really of `NSSet` and `NSMutableSet`) that adds a count for each element in the set.

The `filter` makes sure there are enough of each letter. Anything left in `extra` means `wordTwo` had more instances of a letter than in `wordOne`.

As pointed out, using `allSatisfy`, rather than `filter`, would be more efficient (though trivial on such short words). Change the last two lines to:

```
let good = set2.allSatisfy { set2.count(for: $0) <= set1.count(for: $0) }
print(good ? "Good" : "Bad")

```
I was wondering how I would, and here is an alternative. It's good to have different ways of thinking an issue.

We create a `[Character: (Int, Int)]` where - keys will be the letter, and first tuple value the number of occurences in str1, and second tuple value the number of occurrences in str2.  

Then, we check if all values present in str1 have at leas the same number of occurrences that in str2.

```
var counter: [Character: (Int, Int)] = [:]
counter = str1.reduce(counter) {
    var values = $0
    var tuple: (Int, Int) = $0[$1, default: (0, 0)]
    values[$1] = (tuple.0 + 1, tuple.1)
    return values
}
counter = str2.reduce(counter) {
    var values = $0
    var tuple: (Int, Int) = $0[$1, default: (0, 0)]
    values[$1] = (tuple.0, tuple.1 + 1)
    return values
}
let doesInclude = counter.allSatisfy { _, tuple in
    tuple.0 >= tuple.1
}
print("\(str1) includes all letters from \(str2): \(doesInclude)")

```

The value of counter for `"abc"` vs `"cde"`:

```
["d": (0, 1), "b": (1, 0), "c": (1, 1), "e": (0, 1), "a": (1, 0)]

```

The value of counter for `"battle"` vs `"table"`:

```
["t": (2, 1), "e": (1, 1), "a": (1, 1), "b": (1, 1), "l": (1, 1)]

```