JSFiddle - React, Tailwind, and code Playground
by wangtn18
HTML
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/5.2.0/mocha.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/5.2.0/mocha.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.1.2/chai.min.js"></script>
<div id="mocha"></div>
JavaScript
mocha.setup('bdd');
var expect = chai.expect;
function omitCharAt(str, n) {
//Viết function omitCharAt trả về chuỗi đã được loại bỏ ký tại vị trí n bất kỳ
//Lưu ý cho chuối 'abcd' :
// element 'a'|'b'|'c'|'d'
// index 0 | 1 | 2 | 3
// n = 4 thì chuỗi trả về là 'acd'
// n = 1 ------------------- 'acd'
// n = 2 ------------------- 'abd'
var newStr= str.split('');
console.log(newStr);
newStr.splice(n, 1)
console.log(newStr);
var a= newStr.join('');
console.log(a);
return a;
}
describe('omitCharAt', function () {
it('Omit the first char "a" in string "Hello Quang Dat" (n = 8)', function () {
expect(omitCharAt("Hello Quang Dat", 8)).to.equal("Hello Qung Dat");
});
it('Omit the first char "a" in string "Hello Quang Dat" (n = 68)', function () {
expect(omitCharAt("Hello Quang Dat", 68)).to.equal("Hello Quang Dat");
});
});
mocha.run();