Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Last active January 1, 2016 03:57
Show Gist options
  • Save JavaScript-Packer/3f43516d4af81c62f5bf to your computer and use it in GitHub Desktop.
Save JavaScript-Packer/3f43516d4af81c62f5bf to your computer and use it in GitHub Desktop.
Multiple replacements VIA an array for find & replace terms.
var W,H,A,K;
W = '123456'[$='split']('');
H = 'test this WHAK com www for'[$](' ');
A = '2 is a 1 (1ed 6 3 2, 1 6 3 that), 1ing 6 5.3.4';
K = 0; for(K in W)A=A[$](W[K]).join(H[K]);
document['write'](A);
// this is a test (tested for WHAK this, test for WHAK that), testing for www.WHAK.com
@JavaScript-Packer
Copy link
Author

var W,H,A,K;
H='Some <textarea id="test">www.WHAK.com</textarea>, more Text&Text';
K=[
    [/&/g,"&amp;"],
    [/</g,"&lt;"],
    [/>/g,"&gt;"],
    [/"/g,"&quot;"]
];
for(W in K)H=H.replace(K[W][0],K[W][1]);
alert(H);

@JavaScript-Packer
Copy link
Author

Minified 185 bytes

var W,H,A,K;W="123456"[$="split"](""),H="test this WHAK com www for"[$](" "),
A="2 is a 1 (1ed 6 3 2, 1 6 3 that), 1ing 6 5.3.4",K=0;for(K in W)A=A[$](W[K]).join(H[K]);
document.write(A);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment