learn-co-curriculum / recursion-lab Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
Looks like the test at index-test.js:30-33 doesn't quite belong there.
Due to the
var chai = require('chai');
var sinon = require('sinon');
at the beginning of the test/index-test.js
file, these tests cannot be run in the browser using mocha.run()
. This should either be fixed or noted somewhere in the README.md
myString === myString.substring(0, myString.length - 1) +
// ...and then add the last letter back:
myString[myString.length - 1];
I think this should say 'myString = ' etc. as you're not evaluating equality.
in the test/index-test.js
file there is a test for the addToCart()
function that should not be a part of this lab.
The test for reverseString()
expects there to be 5 recursive calls:
describe('#reverseString', function() {
// ...
it("should make the proper recursive calls", function() {
var reverseString = sinon.spy(window, "reverseString");
reverseString("pizza")
expect(reverseString.callCount).toEqual(5)
})
});
That works for the following correct solution:
function reverseString(string) {
const last = string[string.length - 1];
const remainder = string.substring(0, string.length - 1);
if (remainder.length === 0) {
return last
} else {
return last + reverseString(remainder);
}
} // => calls reverseString 5 times
...but not this (also correct) solution:
function reverseString(string) {
if (string.length === 0) {
return '';
} else {
const last = string[string.length - 1];
const remainder = string.substring(0, string.length - 1);
return last + reverseString(remainder);
}
} // => calls reverseString 6 times
It depends on whether you define your base case as "the final letter" or "no letters left". I think the test should reflect that, as both are valid.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.