Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function trans( s1, s2) {
- var spaceCode = " ".charCodeAt(0);
- var startI = "A".charCodeAt(0);
- // here only symbols with code <= 122
- // if increase this to enough high value will be work with all symbols
- var endI = "z".charCodeAt(0);
- var str1oc = [];
- var str2oc = [];
- for (i = 0; i <= endI; i++) {
- str1oc[i] = 0;
- str2oc[i] = 0;
- }
- for (i = 0; i <= endI; i++) {
- if(s1.charCodeAt(i) != spaceCode) {
- str1oc[s1.charCodeAt(i)]++;
- }
- if(s2.charCodeAt(i) != spaceCode) {
- str2oc[s2.charCodeAt(i)]++;
- }
- }
- for(i = 0; i <= endI; i++) {
- if(str1oc[i] != str2oc[i]) {
- return false;
- }
- }
- return true;
- }
- window.alert(trans("ab", "ba"));
- window.alert(trans("ab ba", "ba a b "));
- window.alert(trans("clockwise", "owe clicks"));
- window.alert(trans("clockwise", "clockwork"));
- //window.alert("a".charCodeAt(0) + " " + " ".charCodeAt(0) + " " + "z".charCodeAt(0));
- //window.alert("A".charCodeAt(0) + " " + " ".charCodeAt(0) + " " + "Z".charCodeAt(0));
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement