Advertisement
Guest User

Untitled

a guest
Jan 29th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. var inputStr;
  2. var bool;
  3. var arr=[];
  4. var arrFiltered=[];
  5. var arrCh=[];
  6. function stringLettersOrganizer (inputStr, bool){
  7. inputStr=document.getElementById('input').value;
  8. if(document.getElementById('bool1').checked){
  9. bool=document.getElementById('bool1').value;
  10. }else {
  11. bool=document.getElementById('bool2').value;
  12. }
  13. var pattern1=/[\W*]/g;
  14. var pattern2=/[\d]/g;
  15. arr=inputStr.split(pattern1);
  16. arrFiltered=arr.filter(function(el){return el;});
  17. for (var ind in arrFiltered) {
  18. arrCh[ind] = arrFiltered[ind].split('');
  19. }
  20.  
  21. for (var i in arrCh) {
  22.  
  23. var res = pattern2.test(arrCh[i]);
  24. if (res === true) {
  25. for (var index in arrCh[i]) {
  26. Number(arrCh[i][index]);
  27. }
  28. }
  29. if (bool === true) {
  30. arrCh[i].sort(function(a,b){
  31. var A = a.toLowerCase();
  32. var B = b.toLowerCase();
  33. if (A < B){
  34. return -1;
  35. }else if (A > B){
  36. return 1;
  37. }else{
  38. return 0;
  39. }
  40.  
  41. });
  42. } else if(bool===false) {
  43. arrCh[i].sort(function (a, b) {
  44. var A = a.toLowerCase();
  45. var B = b.toLowerCase();
  46. if (A < B){
  47. return 1;
  48. }else if (A > B){
  49. return -1;
  50. }else{
  51. return 0;
  52. }
  53.  
  54. });
  55. }
  56. console.log(arrCh[i]);
  57. }
  58.  
  59. console.log(inputStr);
  60. console.log(bool);
  61. console.log(arrFiltered);
  62. console.log(arrCh);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement