js-challenges / recursion-prompts Goto Github PK
View Code? Open in Web Editor NEWRepository of prompts to be solved using recursion
Repository of prompts to be solved using recursion
The tests for prompt 20 need reviewing. Since objects don't promise a particular order, it's tricky determining if the returned object contains all the correct key/value pairs.
Test will fail for "should not use modulo" when the word "modulo" is included in comments.
Add the classic fizzBuzz prompt but require it be solved recursively.
There are many ways to utilize recursion. One approach is to define inner functions that perform recursive behavior and cause side effects. This technique is often simpler to comprehend for those new to recursion. Another approach is to modify the number of parameters a function accepts in order to pass different values through the recursive stack. Both of these techniques are valid uses of recursion, but there are important lessons to be learned from avoiding these two techniques. The student needs to understand how values can be passed through the recursive stack without using recursive subroutines or modifying the number of parameters the function accepts.
Tests already exist requiring each function call itself instead of utilize subroutines, but tests need to be added restricting the number of arguments allowed for each prompt.
it('should return undefined for an empty array', function() {
expect(arraySum([])).to.eql(0); // should be expect(arraySum([])).to.eql(undefined);
});
First off thanks for this challenge set!
So I just noticed that adding in-function comments to Modulo, Multiply, and Divide is caught by the search for '/' operators. Not sure if its worth changing the test for it but a warning above the prompt might be nice.
Best,
Jordan
Hello,
I'm working on the recursion prompts and noticed that the test being done on alternateSign are not working according to specifications.
// their original sign. The first number in the index always needs to be positive.
// alternateSign([2,7,8,3,1,4]) // [2,-7,8,-3,1,-4]
// alternateSign([-2,-7,8,3,-1,4]) // [2,-7,8,-3,1,-4]
After completing the function I noticed that the first element being positive gave off an error. I adjusted the functions code to make the first element in the array negative and then alternate from there. I guess I just wanted to let someone who made it know.
Regards,
Erwin
Tests should be run against an array which also has multiple consecutive digits other than zero in a row.
With the following code, the current automated mocha tests will pass:
var minimizeZeroes = function(array) {
if (array.length <= 1) {
return array;
} else if (array[0] !== array[1]) {
return [array[0]].concat(minimizeZeroes(array.slice(1)));
} else {
return minimizeZeroes(array.slice(1));
}
};
But the above code also minimizes numbers other than zero as well
The following function call :
minimizeZeroes([1, 2, 2, 2, 3, 0, 0, 4, 0, 0])
will produce:
[1, 2, 3, 0, 4, 0]
when it should produce:
[1, 2, 2, 2, 3, 0, 4, 0]
Suggestion for fix:
add multiple consecutive digits which aren't zero to the test
Since tests are being expanded to utilize more spies, tests should be refactored to utilize Mocha's before and after hooks for each prompt.
part1.js line 279
it says "should return the sum of an array of negative integers"
This function tests integers, not arrays. The tests in question pass negative integers as arguments.
The wording from the immediate previous test could probably be adapted.
Add a prompt and tests for cloning objects recursively.
Line 890 of part1.js
Problem 15 compare strings
It uses strings of unequal length 'house' and 'houses' to check that recursive calls equal at least 1.
This is a problem because the first thing many people will do is compare string length. Which is a good habit it to be in.
if the strings compared were 'house' and 'houes' it would test for recursion calls as well as pass a test for equal length. (or even just 'house' and 'house')
Actual:
it('should use recursion by calling self', function() {
compareStr('house', 'houses'); <<-----------------------
expect(compareStr.callCount).to.be.above(1);
});
suggested:
compareStr('house', 'houes');
Problem #12 for 'Greatest Common Divisor' needs a check added to verify the implementation used recursion.
Prompt 32 is a function that counts the number of tags on a page. Need to create tests that check a dummy DOM for tags.
First off, I wanted to say thanks for setting this up, it's been a huge help in practicing recursion! I just wanted to point out a slight issue with one of the tests (lines 435-440) in Part I. A negative base with an even exponent will yield a positive number.
it('should accept negative integer for base', function() {
expect(exponent(-3,4)).to.equal(-81); //should be 81
expect(exponent(-12,5)).to.equal(-248832);
expect(exponent(-7,2)).to.equal(-49); //should be 49
expect(exponent(-7,4)).to.equal(-2401); //should be 2401
});
The tests for prompt #9 Modulo allow for some false positives. Need more tests.
Need to add a test to prompt #34 making sure the array method 'sort' isn't used in the implementation.
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.