JS face Test (ii) (Common algorithm programming)

Source: Internet
Author: User

1. String Turn Hump

Example: Border-bottom-color----> borderBottomColor

var str= "Border-bottom-color";         function Change (str) {            var arr=str.split ("-");              for (var i=1;i<arr.length;i++) {                arr[i]=arr[i].charat (0). toUpperCase () +arr[i]. SUBSTRING (1);            }            STR=arr.join ("");             return str;        }        Console.log (Change (str));//borderbottomcolor

2. Find the most frequently occurring characters and times in a string

For example: the most characters in SDDDRTKJSFKASJDDDJ are D, appearing 6 times

     varStr= "SDDDRTKJSFKKKASJDDDJ"; varMax=0; var Char; functionSearch (str) {varjson={};  for(vari=0;i<str.length;i++){                if(!Json[str[i]]) {Json[str[i]]=Str[i]; }                Else{Json[str[i]]+=Str[i]; }            }             for(vari=0;i<str.length;i++){                if(json[str[i]].length>max) {Max=json[str[i]].length; Char=Str[i]; }} console.log ("The character with the most occurrences is" +Char+ "," +max+ "occurred")} Search (str);

3. Add thousand characters to the string

JS face Test (ii) (Common algorithm programming)

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.