Skip to content

Instantly share code, notes, and snippets.

@simon0191
Created December 6, 2014 19:47
Show Gist options
  • Save simon0191/f24e181fd330483f7063 to your computer and use it in GitHub Desktop.
Save simon0191/f24e181fd330483f7063 to your computer and use it in GitHub Desktop.
var mapa = {'á':'a','é':'e','í':'i','ó':'o','ú':'u','ñ':'n'};
function main(str) {
var sol = '';
for(var i = 0;i<str.length;++i) {
var curr = str[i].toLowerCase();
curr = (mapa[curr] || curr );
if(isAscii(curr)) {
sol+=curr;
} else {
if(sol[sol.length-1] !== '-')
sol+="-";
}
}
if(sol[sol.length-1] === '-') {
sol = sol.substr(0,sol.length-1);
}
return sol;
}
function isAscii(s) {
return s.charCodeAt(0) >= 'a'.charCodeAt(0) && s.charCodeAt(0) <= 'z'.charCodeAt(0);
}
/*
console.log(main('Bogotá JS @ hola mundo ñ'));
console.log(main('Bogotá JS @ hola mundo ñññwerzd v89987 alsdf8()))(=='));*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment