From d0157d93d24c8c7f1a86289efe29e203d98bb072 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 5 Nov 2012 09:01:39 +0000 Subject: 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. --- lib/utils.coffee | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib') 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 = -> -- cgit v1.2.3