Created
July 1, 2013 20:56
-
-
Save aggieben/5904570 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void Main() | |
| { | |
| // Write code to test your extensions here. Press F5 to compile and run. | |
| } | |
| public static class MyExtensions | |
| { | |
| // Write custom extension methods here. They will be available to all queries. | |
| public static double Std(this IEnumerable<double> src) | |
| { | |
| var n = src.Count(); | |
| var avg = src.Average(); | |
| return Math.Sqrt(src.Aggregate(0D, (acc, k) => acc + Math.Pow(selector(k) - avg, 2)) / n); | |
| } | |
| public static double Std<TSource>(this IEnumerable<TSource> src, Func<TSource,double> selector) | |
| { | |
| return src.Select(selector).Std(); | |
| } | |
| } | |
| // You can also define non-static classes, enums, etc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment