Tencent's JavaScript face test

Source: Internet
Author: User
Tags shuffle

Today, sorting out their folders, found that once interviewed Tencent interns were asked to hang the face of the questions, I will be prepared for your reference. It was the handwriting code that was required. Khan, I was in a weak burst!

1, converts the given array to a random array

Array.prototype.shuffle=function () {
        var resultarr=[];
        var len=this.length;
    
        while (len) {
            var _index=parseint (Math.random () *len);
                Resultarr.push (This[_index])//Get one character in the array, put it in the new array for
            (var i=_index;i<len;i++) {//Backward forward move
                this[i]= THIS[I+1];
            }
            len--;
        }
        return resultarr;
    }
   var a=new Array (' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ');
   Alert (A.shuffle ());

2, statistics the number of occurrences of each character in a given string

var a= "Aassdddffffffffggghhhjjjkkkll";
    function counts (str) {
        var obj={};
        for (Var i=0;i<str.length;i++) {
            if (!obj[str[i]]) {
                obj[str[i]]=1
            } else{
             obj[str[i]]++
            }
                
        }
        return obj;
    }
    
    Console.log (Counts (a));//object {a:2, s:2, D:3, F:8, G:3 ...}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/

3, to judge the completion of JS code loading

function Dynamicload ()  
    {  
       var _doc=document.getelementsbytagname (' head ') [0];  
       var script=document.createelement (' script ');  
    
        Script.setattribute (' type ', ' text/javascript ');  
        Script.setattribute (' src ', ' jquery.js ');  
    
        _doc.appendchild (script);  
        Non ie IE        ,
        script.onload=script.onreadystatechange=function () {  
            //non ie IE               , this value is not determined        
           if (! this.readystate| | this.readystate== ' Loaded ' | | this.readystate== ' complete ') {  
             alert (' Done ');  
             Script.onload=script.onreadystatechange=null  
        }}  
        }  
    

4, three columns to achieve the layout:

<! DOCTYPE html>

Author: cnblogs Wimber

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.