<html>
<head>
  <meta charset="utf-8">
  <title>Mocha Tests</title>
  <link href="https://unpkg.com/mocha@5.2.0/mocha.css" rel="stylesheet" />
</head>
<body>
  <div id="mocha"></div>

  <script src="https://unpkg.com/chai/chai.js"></script>
  <script src="https://unpkg.com/mocha@5.2.0/mocha.js"></script>

  <div></div>
  

</body>
</html>
function binarySearch(arr, target) {

  const midpoint = Math.floor(arr.length / 2);

  if (arr[midpoint] === target) return arr[midpoint];
  if (arr[midpoint] < target && arr.length > 1) {
   return binarySearch(arr.slice(midpoint), target);
  }
  if (arr[midpoint] > target && arr.length > 1) {
   return binarySearch(arr.slice(0, midpoint), target);
  }

  return false;
}



mocha.setup('bdd');


var assert = chai.assert;

describe('Binary search algorithm',()=>{
  
  it("item found in the sorted list",()=>{
    assert.equal(4,binarySearch([1,2,3,4,5,6,7],4))
  })

     it("error condition",()=>{
         assert.equal(false,binarySearch([1,2,3,4,5,6,7],23))  
  })
  
  
 
  

  
})



mocha.run()

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.