Bài 49

by wangtn18

HTML

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/5.2.0/mocha.css">
<script src="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.3.0/chai.min.js"></script>
<div id="mocha"></div>

JavaScript

mocha.setup('bdd');
var expect = chai.expect;
//Ket qua bai 15: http://jsfiddle.net/wangtn18/yxkdg3u7/2/
function toNextChar(str) {
	// Viết hàm toNextChar dùng để thay thế mọi ký tự trong một chuỗi thành ký tự theo sau nó trong bảng chữ cái. Ví dụ: "Hello" chuyển thành "Ifmpp"
  // Tham số:
  // - String: chuỗi nhập vào ban đầu.
  var newStr=str.split('');
	var newArr= [];
	for (var index in newStr){
  newArr.push(String.fromCharCode(newStr[index].charCodeAt()	+1));
	}
	
	return newArr.join('');
}

describe("toNextChar", function () {
	it("Return a String with characters that have been replaced", function() {
  	expect(toNextChar('Hello')).to.equal('Ifmmp');
  });
});

mocha.run();