Created
November 19, 2014 04:24
-
-
Save shaohua/cf508a9dd95677b8f8d4 to your computer and use it in GitHub Desktop.
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) { | |
| 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