Skip to content

Instantly share code, notes, and snippets.

@LoadLow
Created September 5, 2014 21:51
Show Gist options
  • Save LoadLow/571a96f3eecf3235108a to your computer and use it in GitHub Desktop.
Save LoadLow/571a96f3eecf3235108a to your computer and use it in GitHub Desktop.
ArraySum.swift
func sumOf(elements:(value:Int, weight:Int)...) -> Int {
var tWeight = 0;
var sum = 0
for element in elements {
sum += element.value;
tWeight += element.weight;
}
return (sum/tWeight);
}
sumOf((value:14,weight:3),(value:20, weight:2),(value:15, weight:1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment