Last active
August 29, 2015 13:57
-
-
Save ksin/9729228 to your computer and use it in GitHub Desktop.
This file contains 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
// --- Function #1 --- | |
// Create sum function which takes someArray as a parameter. | |
// In the function: | |
// -Declare a variable count = 0 | |
// -Iterate through someArray in a for loop, adding each | |
// number in someArray to count | |
// Return count. | |
var sum = function(someArray) { | |
var count = 0; | |
for (var i = 0; i < someArray.length; i++) { | |
count += someArray[i]; | |
} | |
return count; | |
}; | |
// --- Function #2 --- | |
// Create mean function which takes someArray as a parameter | |
// In the function: | |
// -Use the sum function to find the sum of someArray | |
// -Divide the sum by the length of someArray to get the mean | |
// of the array | |
// Return the result of the calculation. | |
var mean = function(someArray) { | |
return sum(someArray) / someArray.length; | |
}; | |
// --- Function #3 --- | |
// Create median function which takes a someArray as a parameter | |
// In the function: | |
// -Sort the array in numerical order. | |
// -Declare a variable midIndex which is the index of the number | |
// in the middle of someArray. This is found by dividing the length | |
// of someArray by 2 and flooring it to account for odd sized arrays. | |
// -IF someArray has an even number of elements (% 2 == 0) | |
// Find the average of the two middle numbers by adding the number in | |
// midIndex and midIndex-1, and then dividing by 2. Return that as the median. | |
// -ELSE someArray has an odd number of elements | |
// Just return the midIndex number in someArray because that's the middle number. | |
var median = function(someArray) { | |
someArray.sort(function(a,b) { return a-b }); | |
var midIndex = Math.floor(someArray.length / 2); | |
if ( someArray.length % 2 == 0 ) { | |
return (someArray[midIndex-1] + someArray[midIndex]) / 2; | |
} | |
else { | |
return someArray[midIndex]; | |
} | |
}; | |
// Reflection | |
// This experience was different as I've never done a group project like this before. | |
// I was able to get the general idea of what my preceding group member wanted me to do. | |
// I quickly realized the goal of the whole project even though I received the project late | |
// in our group. | |
// Pseudocoding was especially important in this exercise as I didn't know the exact assignment | |
// and relied heavily on what my preceding group members told me. | |
// If something wasn't explained clearly, I had to spend extra time looking it up. | |
// In our case, I think I received a little too explicit instructions in the pseudocode. | |
// Because of that, I initially wasn't sure what exactly some of the code was supposed to do even though | |
// I was able to write the code. I feel like a group project shares the work a decent amount | |
// so that no one person is doing too much heavylifting. It's a little nice not having to think | |
// too much about how to work out a project from head to toe, but I'm not sure how realistic splitting | |
// the project between 5 group members is. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment