Revision: 4493
          http://vexi.svn.sourceforge.net/vexi/?rev=4493&view=rev
Author:   clrg
Date:     2013-03-18 01:50:18 +0000 (Mon, 18 Mar 2013)
Log Message:
-----------
Text lines randomizer

Modified Paths:
--------------
    trunk/org.vexi-vapp.examples/src_main/textconvert/main.t

Modified: trunk/org.vexi-vapp.examples/src_main/textconvert/main.t
===================================================================
--- trunk/org.vexi-vapp.examples/src_main/textconvert/main.t    2013-03-15 
03:11:03 UTC (rev 4492)
+++ trunk/org.vexi-vapp.examples/src_main/textconvert/main.t    2013-03-18 
01:50:18 UTC (rev 4493)
@@ -24,6 +24,7 @@
                 <item id="sanc" text="Sane case" />
                 <item id="invc" text="Invert case" />
                 <item id="lowc" text="Lowercase" />
+                <item id="rand" text="Randomize lines" />
             </option>
             <button id="doit" text="Convert Text" />
         </ui:box>
@@ -96,6 +97,24 @@
             return newtext.join("");
         }
         
+        $rand.value = function(t) {
+            var lines = t.split("\n");
+            var rtext = [];
+            var mark = [];
+            var n = lines.length;
+            var i = 0;
+            do {
+                var r = vexi.math.random() * n;
+                if (r == 0) continue;
+                r = vexi.math.ceil(r);
+                if (mark[r-1]) continue;
+                mark[r-1] = true;
+                rtext[i] = lines[r-1];
+                i++;
+            } while (n > i);
+            return rtext.join("\n");
+        }
+        
         // set the default converter
         $sanc.selected = true;
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to