Skip to content

Instantly share code, notes, and snippets.

@PhilKershaw
Created April 1, 2014 21:20
Show Gist options
  • Save PhilKershaw/9923453 to your computer and use it in GitHub Desktop.
Save PhilKershaw/9923453 to your computer and use it in GitHub Desktop.
Simple string interleaving. The resultant string will be as long as the shortest stringx2 and as an added bonus the penultimate character of the first string is appended to the end. All in raw JavaScript.
var string1 = 'ARNFH-U-5728';
var string2 = 'SO06DNV';
var array1 = string1.split('');
var array2 = string2.split('').reverse();
var obfuscated = '';
array1.every(function(e, i, a) {
if (typeof array2[i] === 'undefined') {
obfuscated += array1[(array1.length - 1)];
return false;
}
obfuscated += e + array2[i];
return true;
});
//console.log(obfuscated);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment