Skip to content

Instantly share code, notes, and snippets.

@sunny1304
Last active August 29, 2015 13:55
Show Gist options
  • Select an option

  • Save sunny1304/8772601 to your computer and use it in GitHub Desktop.

Select an option

Save sunny1304/8772601 to your computer and use it in GitHub Desktop.
finding_deviation
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