Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
<head>
  <meta charset="utf-8">
  <title>Binary Search Algorithm using recursion</title>
</head>
<body>

</body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                const binary_Search = (arr, searchValue, low = 0, high = arr.length - 1) => {
  // base case
  if (high < low || arr.length === 0) return -1
  const mid = low + Math.floor((high - low) / 2)
  // If the element is present at the middle
  if (arr[mid] === searchValue) {
    return mid
  }
  // If element is smaller than mid, then
  // it can only be present in left subarray
  if (arr[mid] > searchValue) {
    return binary_Search(arr, searchValue, low, mid - 1)
  }
  // Else the element can only be present in right subarray
  return binary_Search(arr, searchValue, mid + 1, high)
}
 const myArray = [1, 2, 3, 5, 6, 7, 10, 11, 14, 15, 17, 19, 20, 22, 23];
 console.log(binary_Search(myArray, 6));
 console.log(binary_Search(myArray, 16));

              
            
!
999px

Console