Created
March 27, 2012 22:46
-
-
Save mick/2221173 to your computer and use it in GitHub Desktop.
spark like steps for a given 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
| var list = [1,45,23,45,65,6,2]; | |
| var steps = 6; | |
| var packed_list = []; | |
| var min=0, max=0; | |
| for(l in list){ | |
| if(min > list[l]) | |
| min = list[l]; | |
| if(max < list[l]) | |
| max = list[l]; | |
| } | |
| for(l in list){ | |
| packed_list.push(Math.ceil((list[l]/max)*steps)); | |
| } | |
| console.log(packed_list); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment