5 kyu

Calculate Variance

71 of 2,580eerwitt

Description:

Write a function which will accept a sequence of numbers and calculate the variance for the sequence.

The variance for a set of numbers is found by subtracting the mean from every value, squaring the results, adding them all up and dividing by the number of elements.

For example, in pseudo code, to calculate the variance for [1, 2, 2, 3].

mean = (1 + 2 + 2 + 3) / 4
=> 2

variance = ((1 - 2)^2 + (2 - 2)^2 + (2-2)^2 + (3 - 2)^2)  /  4
=> 0.5

The results are tested after being rounded to 4 decimal places using Javascript's toFixed method.

Statistics
Mathematics
Algorithms

More By Author:

Check out these other kata created by eerwitt

Stats:

CreatedOct 22, 2013
PublishedOct 22, 2013
Warriors Trained3455
Total Skips228
Total Code Submissions5499
Total Times Completed2580
CoffeeScript Completions71
JavaScript Completions1229
Haskell Completions82
Python Completions1233
COBOL Completions9
Total Stars39
% of votes with a positive feedback rating86% of 352
Total "Very Satisfied" Votes266
Total "Somewhat Satisfied" Votes70
Total "Not Satisfied" Votes16
Ad
Contributors
  • eerwitt Avatar
  • jhoffner Avatar
  • JohanWiltink Avatar
  • monadius Avatar
  • user9644768 Avatar
  • Glyxerine Avatar
  • albertogcmr Avatar
  • user8436785 Avatar
  • ejini战神 Avatar
  • akar-0 Avatar
Ad