A small question about JavaScript, can someone see what the problem is?

Source: Internet
Author: User

Recently learning JavaScript, there is a very strange problem, first put out the code:

functionBinarySearch () {vararr = [0,1,2,3]; varres = Actbinarysearch (0,3,2, arr); document.write ("<br/>return is" +res);}functionActbinarysearch (Left,right,val,arr) {if(Left >Right ) {document.write ("Do not find"); return-1; }    varMidindex = Math.floor ((left+right)/2);varMidval =Arr[midindex]; if(Val <midval) {Actbinarysearch (left, Midindex-1, Val,arr); }Else if(Val >midval) {Actbinarysearch (Midindex+1, right, Val, arr); }Else{document.write ("Find it" +Midindex); returnMidindex; }}

The simple dichotomy, but the result is very strange, the result is as follows:

Do not know why inconsistent, very confusing, to you to consult.

A small question about JavaScript, can someone see what the problem is?

Related Article

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.