Created
April 18, 2014 06:05
-
-
Save JeuelyFish/11026921 to your computer and use it in GitHub Desktop.
gc1_refactored.js
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
| // User stories for Group Project. | |
| // 1. I want a program that can take any number of integers and add them together | |
| // 2. I want a program that can take any number of integers and calculate their mean (average). | |
| // 3. I want a program that can take any number of integers and find their median number. | |
| // HINT: The name of these "programs" should be: sum, mean, median. | |
| //--------------------- | |
| //PseudoCode | |
| //1. make variable named "sum", take array of integers, produce sum of total. | |
| //2. make variable name "mean", take array of integers, take sum of integers, divide by # of integers | |
| //3. make variable named "median", IF even -> take array of integers, take # of intergers, divide by 2, call result, use result as position in original array to find median. | |
| //If odd -> take array of integers, take # of intergers, divide by 2, call result, round up on result, use result as position in original array to find median. | |
| //-------------------- | |
| //1. | |
| array = []; | |
| var sum = 0; | |
| for (var i = 0; i < array.length; ++i) { | |
| sum += array[i]; | |
| } | |
| //2. | |
| var sum = 0; | |
| for (var i = 0; i < array.length; ++i) { | |
| sum += array[i]; | |
| } | |
| var mean = sum / array.length | |
| //3. | |
| if (array.length % 2 == 0 ) var position = (array.length / 2) | |
| array(position) | |
| elseif var position = Math.Ceil (array.length / 2) | |
| array(position) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment