Reducing arrays into a sum of the helper function results
Approach\nCreate a helper function counting possible products of a number in an array. Return the sum of both arrays being mapped to the power of 2 and reduced 
# Approach\nCreate a helper function counting possible products of a number in an array. Return the sum of both arrays being mapped to the power of 2 and reduced with the helper function.\n\n# Code\n```\nclass Solution {\n\tfunc countProducts(of: Int, inArray: [Int]) -> Int {\n\t\tguard inArray.count > 1 else { return 0 }\n\n\t\tvar res = 0\n\n\t\tfor i in 0...(inArray.count - 2) {\n\t\t\tfor j in (i + 1)...(inArray.count - 1) {\n\t\t\t\tif inArray[i] * inArray[j] == of { res += 1 }\n\t\t\t}\n\t\t}\n\n\t\treturn res\n\t}\n\n\tfunc numTriplets(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\t\tnums1.map { num in num * num }.reduce(0, { acc, num in\n\t\t\tacc + countProducts(of: num, inArray: nums2)\n\t\t}) + nums2.map { num in num * num }.reduce(0, { acc, num in\n\t\t\tacc + countProducts(of: num, inArray: nums1)\n\t\t})\n\t}\n}\n```
['Swift']