JSFiddle - React, Tailwind, and code Playground

by wangtn18

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/q.js/1.4.1/q.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.2.5/mocha.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.2.5/mocha.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.2.0/chai.js"></script>
<div id='mocha'></div>

JavaScript

mocha.setup('bdd');
var expect = chai.expect

/*
Hãy viết một hàm để tìm giá trị lớn nhất có thể đạt được của hiệu 2 số bất kì trong dãy số

Input: là một dãy số.
Output: giá trị lớn nhất có thể đạt được của hiệu 2 số bất kì trong dãy số.

Ví dụ:

Input: [1, 2, 3, 8, 9]
Output: 8 (là hiệu của 9 và 1)

*/

function findmaxDiff(arr){
  // Viết hàm tại đây
  var max = Math.max(...arr);
  var min = Math.min(...arr);
  return max-min
}

describe('findmaxDiff', function() {
  it('maximal difference among all pairs of a array.', function() {
    expect(findmaxDiff([1, 2, 3, 8, 9])).to.equal(8);
  });

  it('maximal difference among all pairs of a array.', function() {
    expect(findmaxDiff([1, 2, 3, 18, 9])).to.equal(17);
  });
  
    it('maximal difference among all pairs of a array.', function() {
    expect(findmaxDiff([13, 2, 3, 8, 9])).to.equal(11);
  });
  
});

mocha.run();