Swift Clean Functional Programming Solution
We can use the functional programming concept of reduce to do this quickly and cleanly:\n\n\nfunc subtractProductAndSum(_ n: Int) -> Int {\n    // Attempts to c
We can use the functional programming concept of [reduce](http://iandundas.com/blog/2016/6/14/swift-basics-reduce) to do this quickly and cleanly:\n\n```\nfunc subtractProductAndSum(_ n: Int) -> Int {\n    // Attempts to convert every character in this string (a digit) to an int.\n\t// `compactMap` removes failed conversions which would return `nil`.\n\t// If the number is well-formatted, this shouldn\'t be a problem.\n\tlet digits = String(n).compactMap { digitAsCharacter in\n\t\tInt(String(digitAsCharacter)\n\t}\n\t\n\t// Start at a value of 1 and multiply every digit to get the product.\n\tlet product = digits.reduce(1) { x, y in x * y }\n\t\n\t// Start at a value of 0 and add every number to get the sum.\n\tlet sum = digits.reduce(0) { x, y in x + y }\n\n\treturn product - sum\n}\n```
[]