This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 14th, 2012  |  syntax: None  |  size: 1.94 KB  |  views: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function find_unique_characters( string ){
  2.     var unique='';
  3.     for(var i=0; i<string.length; i++){
  4.         if(unique.indexOf(string[i])==-1){
  5.             unique += string[i];
  6.         }
  7.     }
  8.     return unique;
  9. }
  10. console.log(find_unique_characters('baraban'));
  11.        
  12. function find_unique_characters( string ){
  13.     var unique='';
  14.     for(var i=0; i<string.length; i++){
  15.         if(string.lastIndexOf(string[i]) == string.indexOf(string[i])){
  16.             unique += string[i];
  17.         }
  18.     }
  19.     return unique;
  20. }
  21. console.log(find_unique_characters('baraban'));​
  22.        
  23. function find_unique_characters( string ) {
  24.     var mapping = {};
  25.     for(var i = 0; i < string.length; i++) {
  26.         var letter = string[i].toString();
  27.         mapping[letter] = mapping[letter] + 1 || 1;
  28.     }
  29.     var unique = '';
  30.     for (var letter in mapping) {
  31.         if (mapping[letter] === 1)
  32.             unique += letter;
  33.     }
  34.  
  35.     return unique;
  36. }
  37.        
  38. function removeDup(str) {
  39.   var arOut = [];
  40.   for (var i=0; i < str.length; i++) {
  41.     var c = str.charAt(i);
  42.     if (c === '_') continue;
  43.     if (str.indexOf(c, i+1) === -1) {
  44.       arOut.push(c);
  45.     }
  46.     else {
  47.       var rx = new RegExp(c, "g");
  48.       str = str.replace(rx, '_');
  49.     }
  50.   }
  51.   return arOut.join('');
  52. }
  53.        
  54. var h={};
  55. "anaconda".split("").
  56.   map(function(c){h[c] |= 0; h[c]++; return c}).
  57.   filter(function(c){return h[c] == 1}).
  58.   join("")
  59.        
  60. function nonRepeaters(s) {
  61.   var h={};
  62.   return s.split("").
  63.     map(function(c){h[c] |= 0; h[c]++; return c}).
  64.     filter(function(c){return h[c] == 1}).
  65.     join("");
  66.  }
  67.        
  68. function find_unique_characters( string ){
  69.     unique=[];
  70.     while(string.length>0){
  71.         var char = string.charAt(0);
  72.         var re = new RegExp(char,"g");
  73.         if (string.match(re).length===1) unique.push(char);
  74.         string=string.replace(re,"");
  75.     }        
  76.     return unique.join("");
  77. }
  78. console.log(find_unique_characters('baraban')); // rn
  79. console.log(find_unique_characters('anaconda')); //cod
clone this paste RAW Paste Data