Several questions of JS's face

Source: Internet
Author: User

String to Hump Function Example: Border-left-width-borderLeftWidth
1     //General Method2     functionFntocamel (str) {3         vararr = Str.split ('-'),4Len =Arr.length,5 i;6          for(vari = 1; i < Len; i++){7Arr[i] = Arr[i].charat (0). toUpperCase () + arr[i].substring (1);8         }9         returnArr.join (");//Note the empty string is comma by defaultTen     } One     //Regular A     functionFntocamelre (str) { -         varRe =/-(\w)/G; -         returnStr.replace (Re,function(arg0, arg1) { the             returnarg1.touppercase (); -         }); -}

Gets the most occurrences of characters and times in a string
1     //General Method2     functionFngetmost (str) {3         varobj = {},4Len =Str.length,5num = 0,6 I,7                 Char;8 9          for(vari = 0; i < Len; i++){Ten             if(Obj[str[i]]) { One Obj[str[i]].push (Str[i]); A}Else{ -Obj[str[i]] =[Str[i]]; -             } the         } -  -          for(Iinchobj) { -             if(Num <obj[i].length) { +num =obj[i].length; -                 Char= Obj[i][0]; +             } A         } at  -         return { -             Char:Char, - Num:num -         }; -     } in  -     //Regular to     functionFngetmostre (str) { +         vararr = str.split (' '), -Re =/(\w) \1+/, thenum = 0, *                 Char; $ Panax Notoginseng Arr.sort (); -str = arr.join (' '); the  +Str.replace (Re,function(arg0, arg1) { A             if(Arg0.length >num) { thenum =arg0.length; +                 Char=arg1; -             } $         }); $          -         return { -             Char:Char, the Num:num -         };Wuyi}

Add a substring to a string for example: 1234567890-123,456,789
1     //General Method2     functionFngetthousand (str) {3         varLen =Str.length,4num = len% 3,5arr = [],6 i;7 8         if(num > 0) {//Mr. Foo the extra characters starting with the string as a whole into the array9Arr.push (str.substring (0, num));Ten         } One  Astr = str.substring (num);//Remove the extra characters -Len =str.length; -  the          for(i = 0; i < len; i + = 3) {//three-A-byte deposit array -Arr.push (Str.substr (i, 3)); -         } -         returnArr.join (); +     } -  +     //Regular A     functionFngetthousandre (str) { at         varRe =/(? = (?! \b) (\d{3}) +$)/G; -  -         returnStr.replace (Re, ', '); -}

Several questions of JS's face

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.