Advertisement
natalyayemelyanova

Cупунков Петр

May 11th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function trans( s1, s2) {
  2.     var spaceCode = " ".charCodeAt(0);
  3.    var startI = "A".charCodeAt(0);
  4.    // here only symbols with code <= 122
  5.    // if increase this to enough high value will be work with all symbols
  6.    var endI = "z".charCodeAt(0);
  7.    var str1oc = [];
  8.    var str2oc = [];
  9.    for (i = 0; i <= endI; i++) {
  10.        str1oc[i] = 0;
  11.        str2oc[i] = 0;
  12.    }
  13.    for (i = 0; i <= endI; i++) {
  14.        if(s1.charCodeAt(i) != spaceCode) {
  15.            str1oc[s1.charCodeAt(i)]++;
  16.        }
  17.        if(s2.charCodeAt(i) != spaceCode) {
  18.            str2oc[s2.charCodeAt(i)]++;
  19.        }
  20.    }
  21.    for(i = 0; i <= endI; i++) {
  22.        if(str1oc[i] != str2oc[i]) {
  23.            return false;
  24.        }
  25.    }
  26.    
  27.  return true;
  28. }
  29.  
  30. window.alert(trans("ab", "ba"));
  31. window.alert(trans("ab ba", "ba a b    "));
  32. window.alert(trans("clockwise", "owe clicks"));
  33. window.alert(trans("clockwise", "clockwork"));
  34. //window.alert("a".charCodeAt(0) + " " + " ".charCodeAt(0) + " " + "z".charCodeAt(0));
  35. //window.alert("A".charCodeAt(0) + " " + " ".charCodeAt(0) + " " + "Z".charCodeAt(0));
  36. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement