Skip to content

Instantly share code, notes, and snippets.

@fb55
Created May 13, 2012 20:52
Show Gist options
  • Save fb55/2690127 to your computer and use it in GitHub Desktop.
Save fb55/2690127 to your computer and use it in GitHub Desktop.
Dropbox Dropquest Chapter 21
var encode = {
1: function(str){
return str
.split("")
.filter(function(s){
return !{D:1, R:1, O:1, P:1, B:1, X:1}[s];
}).join("");
},
2: function(str){
return str.split("").map(function(s){
switch(s){
case "E": return "A";
case "I": return "E";
case "O": return "I";
case "U": return "O";
case "A": return "U";
default: return s;
}
}).join("");
},
5: function(str){
return str.split(" ").map(function(w){
if(w.charAt(0) > "M"){
return w.split("").reverse().join("");
}
return w;
}).join(" ");
},
9: function(str){
return str
.split(" ")
.filter(function(w){ return w.length > 3; })
.join(" ");
}
};
var decode = {
2: function(str){
return str.split("").map(function(s){
switch(s){
case "A": return "E";
case "E": return "I";
case "I": return "O";
case "O": return "U";
case "U": return "A";
default: return s;
}
}).join("");
},
5: function(str){
return str.split(" ").map(function(w){
if(w.substr(-1) > "M"){
return w.split("").reverse().join("");
}
return w;
}).join(" ");
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment