Last active
August 29, 2015 13:55
-
-
Save sunny1304/8772601 to your computer and use it in GitHub Desktop.
finding_deviation
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
| function find_deviation(v, d) | |
| { | |
| if (v.length <= 0) return 0; | |
| start = 0; | |
| medians = []; | |
| arr_length = v.length; | |
| loop_time = arr_length/d; | |
| for(var i=0; i< loop_time; i++){ | |
| temp_arr = v.slice(start, start+d); | |
| find_max = Math.max.apply(null, temp_arr); | |
| find_min = Math.min.apply(null, temp_arr); | |
| medians.push(find_max-find_min); | |
| start+=d; | |
| } | |
| deviation = Math.max.apply(null, medians); | |
| return deviation; | |
| } | |
| test_arr = [-1,-2,-3,-4,-5,-6,-7,-8,-9,-10]; | |
| console.log(find_deviation(test_arr, 3)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment