Coder Social home page Coder Social logo

Comments (9)

romcar avatar romcar commented on June 7, 2024 1

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.

romcar avatar romcar commented on June 7, 2024

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.

mybrainishuge avatar mybrainishuge commented on June 7, 2024

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.

romcar avatar romcar commented on June 7, 2024

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.

mybrainishuge avatar mybrainishuge commented on June 7, 2024

Is this your corrected code or the code that returned the false positive? @romcar

from recursion-prompts.

romcar avatar romcar commented on June 7, 2024

from recursion-prompts.

mybrainishuge avatar mybrainishuge commented on June 7, 2024

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.

romcar avatar romcar commented on June 7, 2024

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.

mybrainishuge avatar mybrainishuge commented on June 7, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.