Created
December 5, 2014 06:21
-
-
Save spenserfiller/aa21ff963541c40c3462 to your computer and use it in GitHub Desktop.
Measures 'dips' in array
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 waterfall(original_array, do_it_again_boolean){ | |
| var current_high = 0; | |
| var current_rough_area = 0; | |
| var fill_counter = 0; | |
| var final_adjusted_area = 0; | |
| var reverse = do_it_again_boolean; | |
| for(var i=0; i< original_array.length; i++){ | |
| if (i === 0 || original_array[i] >= current_high){ | |
| current_high = original_array[i]; | |
| current_rough_area -= (original_array[i] - current_high) * fill_counter; | |
| fill_counter = 0; | |
| final_adjusted_area += current_rough_area; | |
| current_rough_area = 0; | |
| } else if (i === original_array.length-1){ | |
| current_rough_area = original_array.slice(original_array.length-fill_counter-2).reverse(); | |
| final_adjusted_area += waterfall(current_rough_area, true); | |
| } | |
| else { | |
| current_rough_area += current_high - original_array[i]; | |
| fill_counter ++ ; | |
| } | |
| } | |
| return final_adjusted_area; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment