Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RoastBeefKazenakis/81f91a359131bbde74aa2229a4b8512c to your computer and use it in GitHub Desktop.
Save RoastBeefKazenakis/81f91a359131bbde74aa2229a4b8512c to your computer and use it in GitHub Desktop.
Sum CodeChallenge 11/13/19 by: Thomas Sabino-Benowitz
func sum(_ nums: [Int], _ target: Int) -> [Int] {
var sumIndex: [Int] = []
for x in 0..<target {
for y in 0...x{
if (nums.firstIndex(of: x) != nil) {
if (nums.firstIndex(of: y) != nil) {
if x + y == target {
sumIndex.append(nums.firstIndex(of: y)!)
sumIndex.append(nums.firstIndex(of: x)!)
}
}
}
}
}
return sumIndex
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment