aboutsummaryrefslogtreecommitdiffstats
path: root/lib/utils.coffee
diff options
context:
space:
mode:
authorStephen Blott2012-11-05 09:01:39 +0000
committerStephen Blott2012-11-05 09:01:39 +0000
commitd0157d93d24c8c7f1a86289efe29e203d98bb072 (patch)
treeaaaab07f3951dde1d8ab74f57b4a7bfdea0a98f1 /lib/utils.coffee
parente5aa0993b7353b16308f7dbfd0a1e217264c2cae (diff)
downloadvimium-d0157d93d24c8c7f1a86289efe29e203d98bb072.tar.bz2
Factor pushMatchingRanges, improve comments/tests
1. Factor out `pushMatchingRanges`: This then allows us to ... 2. Add unit tests for `pushMatchingRanges` In effect, these tests verify where matches are highlighted in suggestions. 3. Added Utils.zip. This helps simplify `pushMatchingRanges` unit tests. 4. Improve comments.
Diffstat (limited to 'lib/utils.coffee')
-rw-r--r--lib/utils.coffee8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/utils.coffee b/lib/utils.coffee
index e89d0aa2..c997b74b 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -126,6 +126,14 @@ Utils =
return 1
0
+ # Zip two (or more) arrays:
+ # - Utils.zip([ [a,b], [1,2] ]) returns [ [a,1], [b,2] ]
+ # - Length of result is `arrays[0].length`.
+ # - Adapted from: http://stackoverflow.com/questions/4856717/javascript-equivalent-of-pythons-zip-function
+ zip: (arrays) ->
+ arrays[0].map (_,i) ->
+ arrays.map( (array) -> array[i] )
+
# This creates a new function out of an existing function, where the new function takes fewer arguments. This
# allows us to pass around functions instead of functions + a partial list of arguments.
Function::curry = ->