Flat Previous Topic | Next Topic
Stefan
Posted on: 8/16/2012 1:49 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 263
Re: Macro: Paste/Merge/Join two list together side-by-side
Merge two list together side-by-side RANDOM-ized

Hi folks, I was asked how to
random the two list together side-by-side.

Here is my answer:

``````
//EmEditor Script (JavaScript)
// Merge two list together side-by-side RANDOM-ized
// shuffle intermix stochastic stochastically
// (see examples) Writes result to new document.

//=======================================================
//============ U S E R S E T T I N G S ==================

// Separate your two input list by at least 5 #'s
// Example input:
//  JAMES
//  JOHN   <<< Left side in output
//  WILLIAM
//  RICHARD
//  CHARLES
//  ##########  <<< Five or more #'s, but not less!
//  MARY
//  PATRICIA
//  LINDA  <<< Right side in output
//  BARBARA
//  ELIZABETH
Separator = "#####";

// Delimiter to be used for separating
// consecutive values on a single line.
// Join both input lists side-by-side,
// separated by that sign in the output
// Example output:
//  WILLIAM + ELIZABETH
//  CHARLES + PATRICIA
//  RICHARD + BARBARA
//  JAMES + MARY
//  JOHN + LINDA
//  or
//  JOHN + BARBARA
//  JAMES + PATRICIA
//  RICHARD + ELIZABETH
//  CHARLES + LINDA
//  WILLIAM + MARY
//  or
//  WILLIAM + PATRICIA
//  JAMES + BARBARA
//  RICHARD + ELIZABETH
//  CHARLES + LINDA
//  JOHN + MARY
//  or...
//
Delimeter = " + ";

//===========================================================
//===========================================================
//============ T H E   S C R I P T ==========================

document.selection.SelectAll();
sel = document.selection.Text; //alert(sel);
Lines = sel.split("\r\n");     //Using Windows Line Enders here
SeparatorFound = false;
arrONE = new Array();
arrTWO = new Array();
arrOUT = new Array();

for(L = 0, Ls = Lines.length; L < Ls; L++){
if (Lines[L].indexOf(Separator) != -1){
SeparatorFound = true; continue; //SKIP
}
if (SeparatorFound==false){
arrONE[L] = Lines[L];
}else{
arrTWO[L] = Lines[L];
}
}

//Randomize the order of the array:
arrONE.sort( function() {return 0.5 - Math.random()} );
arrTWO.sort( function() {return 0.5 - Math.random()} );
//Join the arrays side-by-side:
for(idx=0,Len=arrONE.length; idx<Len; idx++){
arrOUT[idx] = arrONE[idx] + Delimeter + arrTWO[idx];
}
//============ O U T P U T =================================
OUT = arrOUT.join("\r\n");

//Works with EmEditor:
editor.NewFile();
document.write(OUT);

//The End
//===========================================================
``````

shuffle intermix stochastic stochastically random randomized
 Flat Previous Topic | Next Topic

Subject Poster Date
Macro: Paste/Merge/Join two list together side-by-side Stefan 8/15/2012 7:24 am
» Re: Macro: Paste/Merge/Join two list together side-by-side Stefan 8/16/2012 1:49 am

 Register To Post ________________Announcements  - Announcements ________________EmEditor Core  - Questions and Answers about EmEditor Core   - Regular Expressions   - EmEditor Core Enhancement Suggestions   - EmEditor Core Bug Reports ________________Plug-ins  - Questions and Answers about Plug-ins   - Enhancement Suggestions about Plug-ins   - Plug-in Bug Reports ________________Macros  - Questions and Answers about Macros   - Enhancement Suggestions about Macros   - Macro Samples ________________Beta Room  - Beta Version Bug Reports ________________User Comments  - Testimonials ________________Other Topics  - Other Programs   - General