Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var inputStr;
- var bool;
- var arr=[];
- var arrFiltered=[];
- var arrCh=[];
- function stringLettersOrganizer (inputStr, bool){
- inputStr=document.getElementById('input').value;
- if(document.getElementById('bool1').checked){
- bool=document.getElementById('bool1').value;
- }else {
- bool=document.getElementById('bool2').value;
- }
- var pattern1=/[\W*]/g;
- var pattern2=/[\d]/g;
- arr=inputStr.split(pattern1);
- arrFiltered=arr.filter(function(el){return el;});
- for (var ind in arrFiltered) {
- arrCh[ind] = arrFiltered[ind].split('');
- }
- for (var i in arrCh) {
- var res = pattern2.test(arrCh[i]);
- if (res === true) {
- for (var index in arrCh[i]) {
- Number(arrCh[i][index]);
- }
- }
- if (bool === true) {
- arrCh[i].sort(function(a,b){
- var A = a.toLowerCase();
- var B = b.toLowerCase();
- if (A < B){
- return -1;
- }else if (A > B){
- return 1;
- }else{
- return 0;
- }
- });
- } else if(bool===false) {
- arrCh[i].sort(function (a, b) {
- var A = a.toLowerCase();
- var B = b.toLowerCase();
- if (A < B){
- return 1;
- }else if (A > B){
- return -1;
- }else{
- return 0;
- }
- });
- }
- console.log(arrCh[i]);
- }
- console.log(inputStr);
- console.log(bool);
- console.log(arrFiltered);
- console.log(arrCh);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement