Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. Oa = Oaxy
  2. and au = auxy
  3. Gardenhire = Gardxy
  4.  
  5. Parker = Parkxy
  6.  
  7. Arney = Arnxy
  8.  
  9. There are 4 rules.
  10. 1. The name cuts off at the second vowel and is replaced by 'xy.'
  11. 2. connected vowels count as a single and should stay together.
  12. 3. EXCEPTION: when the last letter is 'x' another 'x' is not added.
  13. 4. Names with only two connected vowels should have "xy" added to the end
  14.  
  15. function doit(userName) {
  16. var temp = userName.toLowerCase();
  17. var vowels = "aeiouy"
  18. var count = 0;
  19.  
  20. if(userName) {
  21. for(var i=0; i<temp.length; i++) {
  22.  
  23. if( vowels.indexOf(temp.charAt(i)) > -1 ) {
  24. count++;
  25. if(count==1) {
  26. while( vowels.indexOf(temp.charAt(++i)) != -1 );
  27. i--;
  28. } else
  29. break;
  30. }
  31. }
  32.  
  33. userName = userName.substr(0, i);
  34. if( userName.charAt(userName.length-1) == 's' )
  35. userName += "y";
  36. else
  37. userName += "sy";
  38. } else
  39. userName = 'Take a lap, Dummy';
  40. return userName.toUpperCase();
  41.  
  42. }
  43.  
  44. var word = "anumap";
  45. var transformed = word.replace(/(w+[aeiou]+).*/i, " $1xy");
  46.  
  47. function doit(userName) {
  48. var str = userName || "";
  49. var vowels = ["a","e","i","o","u"];
  50. var suffix = "xy";
  51.  
  52. var str_arr = str.split("");
  53. var str_arr_rev = str_arr.reverse();
  54.  
  55. $.each(str_arr_rev, function (i, item) {
  56. if ($.inArray(item.toLowerCase(), vowels) > -1) {
  57. last_vowel_index = i;
  58. return false;
  59. }
  60. });
  61.  
  62. if (last_vowel_index == -1) {
  63. $.each(str_arr_rev, function (i, item) {
  64. if (item.toLowerCase() == "y") {
  65. last_vowel_index = i;
  66. return false;
  67. }
  68. });
  69. }
  70.  
  71. if (last_vowel_index > -1)
  72. str_arr_rev[last_vowel_index] = str_arr_rev[last_vowel_index] + suffix;
  73.  
  74. return str_arr_rev.reverse().join("");
  75. }
  76.  
  77. Oa = Oaxy and au = auxy -Anup
  78.  
  79. <input type="text" value="" /><br />
  80. <div id="name"></div>
  81.  
  82. $(function () {
  83. $("input").on("change", function(e) {
  84. $("#name")
  85. .html(function (index, o) {
  86. var v = /[aeiou]+.$/gi;
  87. var o = $(e.target).val();
  88. var n = v.test(o);
  89. return (n ? String(o.replace(/[^aeiou]$/gi, "") + "xy").toUpperCase() : o)
  90. });
  91. });
  92. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement