Comments (9)
I accept the challenge, when I have more time as of right now I'm super busy. Sorry to take up your time. Thanks for responding though.
from recursion-prompts.
Nevermind, I see what I did. It was a simple ternary statement. Although it is very strange that I could still pass those test with incorrect values. Sorry about that!
from recursion-prompts.
Thanks for messaging me, @romcar. I'm glad you figured it out on your own. Do you mind providing more detail for the false positive you received? It looks like there may have been a bug in Chai's deep equality assertion. I'm wondering if you came across a case where their algorithm for checking deep equality failed.
from recursion-prompts.
Well here's my code:
var alternateSign = function(array) {
let temp = array.slice();
let element = temp.shift();
if(array.length === 0){
return [];
}
//if array length is odd make the element positive
if(array.length%2 !== 0){
//is the number positive
return [element > 0 ? 0-element : element].concat(alternateSign(temp));
} else {
//if the array length is even make the element positive
//is the element negative
return [element < 0 ? 0-element: element].concat(alternateSign(temp));
}
return temp;
/*Almost gave up on this one*/
};
I checked the chai code and it tests to see if the array starts with a positive number. With my code, as the problem recursively flows it determines the sign of the element in the array according to the length of the array. Right now my arrays come out starting with negative values then continuing alternation from there.
The second if statement (array.length) can be switched to === to make the array being with a positive number. But the test will fail. I'm sure it's a bug involving the deep equality assertion. No matter how I changed my code it will only pass if the alternation is neg, pos, neg, ...
from recursion-prompts.
Is this your corrected code or the code that returned the false positive? @romcar
from recursion-prompts.
from recursion-prompts.
I ran the code you provided above and it returns the correct output. Can you help me produce the false positive you saw? @romcar
from recursion-prompts.
When I type in:
alternateSign([3, 3, 4])
-->(3) [-3, 3, -4]```
I ran a few console.log test and see that they come out positive but when I type in the above in the console I get a return value of [-3, 3, -4].
from recursion-prompts.
For an input of [3, 3, 4]
, the output should be [3, -3, 4]
. The numbers returned all even indices should be positive. The numbers returned in all odd indices should be negative. If that's not the output your implementation is returning, then I think you have a bug to fix. :)
This is not an input I included in the tests, so it can't be a bug in the tests. The tests I included are intended to be a guide, but don't account for all possible edge cases. If you want to add tests to account for some edge cases, I'd be thrilled for you to make a PR and I'll review it.
from recursion-prompts.
Related Issues (18)
- Review tests for prompt #20 HOT 1
- Need tests for prompt #32 'Count Tags' HOT 2
- Check that 'sort' isn't used in #38 Merge Sort HOT 2
- Need better tests for #9 Modulo HOT 1
- Prompt 3 Should return undefined for empty array instead expects 0 HOT 1
- Comments fail it("should not use complex math") HOT 1
- Add tests to restrict number of arguments allowed HOT 1
- Add recursive fizzBuzz HOT 1
- Refactor to use before and after hooks for spies HOT 1
- Expand readme with clearer instructions HOT 1
- Add recursive cloneObject HOT 1
- Recursion Test - Part 1 (Exponent) HOT 6
- Test for sumBelow has incorrect text HOT 12
- Test for recursion on 15. Compare Strings uses strings of unequal length HOT 3
- isEven -- Modulo issue HOT 5
- Add check for recursion to problem 12 HOT 1
- Prompt #34 - Minimize Zeroes - needs more robust testing HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from recursion-prompts.