npm install
npm testFollow the TDD rules:
- You can't write any production code until you have first written a failing unit test.
- You can't write more of a unit test than is sufficient to fail, and not compiling is failing.
- You can't write more production code than is sufficient to pass the currently failing unit test.
Follow the RGR cycle.
- Red - create a unit test that fails.
- Green - Write code that makes the test pass.
- Refactor - Clean up the mess you just made.
With the actual tests described below, try to not read ahead. Focus on the above and not on the final code.
Count(null) ==> returns 0Count(" \n\n\t\r ") ==> returns 0Count("Hello") ==> returns 1Count("Hello world") ==> returns 2Count(" \nHello \r ") ==> returns 1Count("Hello crazy \n world") ==> returns 3Count("Hello world in world") ==> returns 3Count("Hello world hello") ==> returns 2Count("Hello world hello.") ==> returns 2Count("Hello (world) - 123.") ==> returns 3Count("Allô? Allo est la fin.") ==> returns 4