Skip to content

Instantly share code, notes, and snippets.

@Pholisa-Fatyela
Created March 20, 2020 15:14
Show Gist options
  • Save Pholisa-Fatyela/80cf52f4c7f69620cd4cf61d8cd1bcf7 to your computer and use it in GitHub Desktop.
Save Pholisa-Fatyela/80cf52f4c7f69620cd4cf61d8cd1bcf7 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/risabuv
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.2.0/mocha.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.2.0/mocha.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.5.0/chai.min.js"></script>
<br>
<br>
<br>
<h3>Please note !</h3>
This function is a modifed version of the bootcamp one. Read the code comments to see how it's different.
<br>
<br>
<div id="mocha"></div>
<script>
// the mocha test style to use - we use BDD - Behviour Driven Development
mocha.setup('bdd');
//ensure the assert function is available
var assert = chai.assert;
</script>
<script id="jsbin-javascript">
// don't change the countRegNumber function
// Note that valid reg numbers starts with CY or CJ
function countRegNumber(regList){
var counter = 0;
const regNumbers = regList.split(",");
for (var i=0;i<regNumbers.length;i++) {
var regNumber = regNumbers[i].trim();
if (regNumber.startsWith("CL")) {
return 0;
}
if (regNumber.startsWith("CY")) {
counter++;
} else if (regNumber.startsWith("CJ")) {
counter++;
}
}
return counter;
}
// don't change any code above this line
describe("The countRegNumber function ", function() {
// don't change code above this line
it("should return 1 for 'CY 123-223'", function() {
// change anything in here to make the test pass
assert.equal(1, countRegNumber("CY 123-223, CA 123-123"));
});
it("should return 2 - but the parameter needs work'", function() {
var EXPECTED_COUNT = 2;
// only change code below this line in this function to make this test pass
assert.equal(EXPECTED_COUNT, countRegNumber("CY 123-123, CY 123-123"));
});
it("should return 5 - but the parameter needs work'", function() {
var EXPECTED_COUNT = 5;
// only change code below this line in this function to make this test pass
assert.equal(EXPECTED_COUNT, countRegNumber("CY 123-123, CJ 123-123, CY 123-123, CJ 123-123, CY 123-123, CA 123-123"));
});
it("should return 3 - but there is a curveball'", function() {
var EXPECTED_COUNT = 3;
// only change code below this line in this function to make this test pass
// change one of the reg numbers in the string below to fix this test
assert.equal(EXPECTED_COUNT, countRegNumber("CY 123-123, CA 123-123, CY 123-123, CA 123-123, CY 123-123, CA 123-123"));
});
});
mocha.checkLeaks();
mocha.run();
</script>
<script id="jsbin-source-javascript" type="text/javascript">// don't change the countRegNumber function
// Note that valid reg numbers starts with CY or CJ
function countRegNumber(regList){
var counter = 0;
const regNumbers = regList.split(",");
for (var i=0;i<regNumbers.length;i++) {
var regNumber = regNumbers[i].trim();
if (regNumber.startsWith("CL")) {
return 0;
}
if (regNumber.startsWith("CY")) {
counter++;
} else if (regNumber.startsWith("CJ")) {
counter++;
}
}
return counter;
}
// don't change any code above this line
describe("The countRegNumber function ", function() {
// don't change code above this line
it("should return 1 for 'CY 123-223'", function() {
// change anything in here to make the test pass
assert.equal(1, countRegNumber("CY 123-223, CA 123-123"));
});
it("should return 2 - but the parameter needs work'", function() {
var EXPECTED_COUNT = 2;
// only change code below this line in this function to make this test pass
assert.equal(EXPECTED_COUNT, countRegNumber("CY 123-123, CY 123-123"));
});
it("should return 5 - but the parameter needs work'", function() {
var EXPECTED_COUNT = 5;
// only change code below this line in this function to make this test pass
assert.equal(EXPECTED_COUNT, countRegNumber("CY 123-123, CJ 123-123, CY 123-123, CJ 123-123, CY 123-123, CA 123-123"));
});
it("should return 3 - but there is a curveball'", function() {
var EXPECTED_COUNT = 3;
// only change code below this line in this function to make this test pass
// change one of the reg numbers in the string below to fix this test
assert.equal(EXPECTED_COUNT, countRegNumber("CY 123-123, CA 123-123, CY 123-123, CA 123-123, CY 123-123, CA 123-123"));
});
});
mocha.checkLeaks();
mocha.run();</script></body>
</html>
// don't change the countRegNumber function
// Note that valid reg numbers starts with CY or CJ
function countRegNumber(regList){
var counter = 0;
const regNumbers = regList.split(",");
for (var i=0;i<regNumbers.length;i++) {
var regNumber = regNumbers[i].trim();
if (regNumber.startsWith("CL")) {
return 0;
}
if (regNumber.startsWith("CY")) {
counter++;
} else if (regNumber.startsWith("CJ")) {
counter++;
}
}
return counter;
}
// don't change any code above this line
describe("The countRegNumber function ", function() {
// don't change code above this line
it("should return 1 for 'CY 123-223'", function() {
// change anything in here to make the test pass
assert.equal(1, countRegNumber("CY 123-223, CA 123-123"));
});
it("should return 2 - but the parameter needs work'", function() {
var EXPECTED_COUNT = 2;
// only change code below this line in this function to make this test pass
assert.equal(EXPECTED_COUNT, countRegNumber("CY 123-123, CY 123-123"));
});
it("should return 5 - but the parameter needs work'", function() {
var EXPECTED_COUNT = 5;
// only change code below this line in this function to make this test pass
assert.equal(EXPECTED_COUNT, countRegNumber("CY 123-123, CJ 123-123, CY 123-123, CJ 123-123, CY 123-123, CA 123-123"));
});
it("should return 3 - but there is a curveball'", function() {
var EXPECTED_COUNT = 3;
// only change code below this line in this function to make this test pass
// change one of the reg numbers in the string below to fix this test
assert.equal(EXPECTED_COUNT, countRegNumber("CY 123-123, CA 123-123, CY 123-123, CA 123-123, CY 123-123, CA 123-123"));
});
});
mocha.checkLeaks();
mocha.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment