string reduction
http://www.interviewstreet.com/recruit/challenges/solve/view/4e1491425cf10/4eac48496bee2
JavaScript
var input = 'cabb',
possible = ['a', 'b', 'c'];
function process(s) {
if (s.length === 1) {
output = s;
return;
}
for (var len = s.length, i = 0, j = 1; j < len; i++, j++) {
output += replace(s[i], s[j]);
}
alert(output);
}
function replace(char1, char2) {
if (char1 === char2) {
return char1 + char2;
}
for (var i = 0; i < possible.length; i++) {
if (possible[i] !== char1 && possible[i] !== char2) {
return possible[i];
}
}
}
//alert(replace('a','b'));
alert(process(input));