Created
November 15, 2012 16:17
-
-
Save jeffschwartz/4079460 to your computer and use it in GitHub Desktop.
My implementation of String Permutation in response to the coding challenge found @ http://java.dzone.com/articles/thursday-code-puzzler-string-0#comment-90277
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created with JetBrains WebStorm. | |
* User: jeffrey | |
* Date: 11/14/12 | |
* Time: 3:53 PM | |
* To change this template use File | Settings | File Templates. | |
*/ | |
var perm = function(window, undefined) { | |
"use strict"; | |
// var s = 'abcdefghijklmnopqrstuvwxyz'; | |
var s = 'abccba', | |
i, | |
ii, | |
len, | |
temps = '', | |
list = [], | |
result; | |
/* | |
* Make one pass of the string for each one of its characters, bypassing the current character. | |
*/ | |
for(i = 0, len = s.length; i < len; i += 1) { | |
for(ii = 0; ii < len; ii += 1) { | |
if(s[ii] !== s[i]) { | |
temps = s[i] + s[ii]; | |
list.push(temps); | |
console.log(temps); | |
temps = ''; | |
} | |
} | |
} | |
console.log(list); | |
result = new JS.SortedSet(list); | |
result.forEach(function(x) { | |
console.log(x); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment