Skip to content

Instantly share code, notes, and snippets.

@shaohua
Created November 19, 2014 04:24
Show Gist options
  • Select an option

  • Save shaohua/cf508a9dd95677b8f8d4 to your computer and use it in GitHub Desktop.

Select an option

Save shaohua/cf508a9dd95677b8f8d4 to your computer and use it in GitHub Desktop.
function find_deviation(v, d) {
var seq = [],
diff = 0,
seqMax = [];
for(var i=0; i<v.length + 1 -d; i++){
console.log('v', v);
seq = v.slice(i, i + d);
console.log('seq', seq);
seq.sort(function(a, b){
return a-b;
});
diff = seq[seq.length-1] - seq[0];
seqMax.push( diff );
console.log('diff', diff);
}
seqMax.sort();
var output = seqMax[seqMax.length - 1];
console.log(output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment