Skip to content

feat(euler-problem): Add tests and solution for Problem 4: Largest palindrome product#15856

Merged
BerkeleyTrue merged 2 commits intofreeCodeCamp:stagingfrom
AungMyoKyaw:feat/eluer-prob-4
Jan 16, 2018
Merged

feat(euler-problem): Add tests and solution for Problem 4: Largest palindrome product#15856
BerkeleyTrue merged 2 commits intofreeCodeCamp:stagingfrom
AungMyoKyaw:feat/eluer-prob-4

Conversation

@AungMyoKyaw
Copy link
Copy Markdown
Contributor

@AungMyoKyaw AungMyoKyaw commented Sep 7, 2017

Add tests and solution for Problem 4: Largest palindrome product

Pre-Submission Checklist

  • Your pull request targets the staging branch of freeCodeCamp.
  • Branch starts with either fix/, feature/, or translate/ (e.g. fix/signin-issue)
  • You have only one commit (if not, squash them into one commit).
  • All new and existing tests pass the command npm test. Use git commit --amend to amend any fixes.

Type of Change

  • Small bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds new functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Add new translation (feature adding new translations)

Checklist:

  • Tested changes locally.
  • Closes currently open issue (replace XXXX with an issue no): Closes #XXXX

Description

@BerkeleyTrue BerkeleyTrue added the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label Sep 7, 2017
@QuincyLarson
Copy link
Copy Markdown
Contributor

@AungMyoKyaw This is a nice start. It looks like you got a build error. Is this passing for you locally when you run npm run test?

Also, could you share a working solution here to make this easier to QA?

@camperbot
Copy link
Copy Markdown
Contributor

@AungMyoKyaw updated the pull request.

@camperbot
Copy link
Copy Markdown
Contributor

@AungMyoKyaw updated the pull request.

@raisedadead raisedadead added status: blocked In a transient & temporary hold. and removed status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. labels Oct 20, 2017
@QuincyLarson
Copy link
Copy Markdown
Contributor

@AungMyoKyaw Any luck getting this to pass locally?

@AungMyoKyaw
Copy link
Copy Markdown
Contributor Author

Hi @QuincyLarson
When i run test locally,I got the following error message.

Create a Circular Queue

✖ SyntaxError: Octal literals are not allowed in strict mode.
✖ SyntaxError: Octal literals are not allowed in strict mode.

@QuincyLarson
Copy link
Copy Markdown
Contributor

@AungMyoKyaw It looks like Node may be interpreting some of your code as octals. This Stack Overflow answer may be relevant: https://stackoverflow.com/questions/23609042/how-to-avoid-octal-literals-are-not-allowed-in-strict-mode-with-createwritestr

@texas2010 Do you know what might be causing this?

@AungMyoKyaw
Copy link
Copy Markdown
Contributor Author

Hi @QuincyLarson ,
All test can pass, if no solution is provided.
Here is my solution.

 "const largestPalindromeProduct = (digit)=>{\n  let start = 1;\n  let end = Number(`1e${digit}`) - 1;\n let palindrome = [];\n  for(let i=start;i<=end;i++){\n    for(let j=start;j<=end;j++){\n      let product = i*j;\n      let palindromeRegex = new RegExp('\\b(\\d)(\\d?)(\\d?).?\\3\\2\\1\\b','gi');\n      palindromeRegex.test(product) && palindrome.push(product);\n    }\n }\n return Math.max(...palindrome);\n}"

Here is more readable version

const largestPalindromeProduct = (digit)=>{
  let start = 1;
  let end = Number(`1e${digit}`) - 1;
  let palindrome = [];
  for(let i=start;i<=end;i++){
    for(let j=start;j<=end;j++){
    	let product = i*j;
    	let palindromeRegex = new RegExp('\\b(\\d)(\\d?)(\\d?).?\\3\\2\\1\\b','gi');
    	palindromeRegex.test(product) && palindrome.push(product);
     }
  }
  return Math.max(...palindrome);
}

@QuincyLarson
Copy link
Copy Markdown
Contributor

I've granted @alvinkl write access to this repo. He has agreed to help QA your pull requests since he knows more about the process of importing and improving these Project Euler challenges than anyone.

@raisedadead
Copy link
Copy Markdown
Member

@QuincyLarson I am not sure (for my lack of expertise on the topic) what this needs for a QA? Are we able to either merge or close this?

@scissorsneedfoodtoo
Copy link
Copy Markdown
Contributor

Hi there @AungMyoKyaw. I was asked to take a look at your pull request. I have it running fine here on my local machine, and npm test no longer throws any errors. Seems like the build errors you were getting before were from another problem altogether. Everything with your submission looks good here!

@QuincyLarson, is there a way to trigger another Travis-CI build on your end? Or would it be best for @AungMyoKyaw to close and reopen this pull request? Maybe squash and push an empty commit? I'm not sure what would be best in this case.

@raisedadead
Copy link
Copy Markdown
Member

@scissorsneedfoodtoo this pull request simply needs a re-base against the current staging.

@AungMyoKyaw you need to

git checkout feat/eluer-prob-4
git pull --rebase upstream staging
git push origin feat/eluer-prob-4

That will re-base the code and trigger the build again.

@scissorsneedfoodtoo
Copy link
Copy Markdown
Contributor

@raisedadead Thank you! I'll definitely keep that in mind.

@AungMyoKyaw, good luck with the new build.

@camperbot
Copy link
Copy Markdown
Contributor

@AungMyoKyaw updated the pull request.

@AungMyoKyaw
Copy link
Copy Markdown
Contributor Author

Hi @QuincyLarson , @raisedadead , @scissorsneedfoodtoo
Sorry for my late reply
I am updating my pull request.

@scissorsneedfoodtoo
Copy link
Copy Markdown
Contributor

@AungMyoKyaw, no worries! Thank you for updating your pull request.

Sorry the build is still failing. It seems to be a problem with another challenge, possibly Create a Priority Queue Class. I'm looking into it now. Hope we can get this sorted out and merge your pull request soon!

@scissorsneedfoodtoo
Copy link
Copy Markdown
Contributor

scissorsneedfoodtoo commented Jan 3, 2018

@AungMyoKyaw, I think I figured out the problem.

If you change your solution to this, then your pull request should have no problems passing the tests:

"const largestPalindromeProduct = (digit)=>{\n  let start = 1;\n  let end = Number(`1e${digit}`) - 1;\n let palindrome = [];\n  for(let i=start;i<=end;i++){\n    for(let j=start;j<=end;j++){\n      let product = i*j;\n      let palindromeRegex = /\\b(\\d)(\\d?)(\\d?).?\\3\\2\\1\\b/gi;\n      palindromeRegex.test(product) && palindrome.push(product);\n    }\n }\n return Math.max(...palindrome);\n}"

I believe the problem was that the new RegExp function. Seems like it wasn't allowing proper character escapes, which caused the error.

Anyway, you should be good to go after that change!

@camperbot
Copy link
Copy Markdown
Contributor

@raisedadead updated the pull request.

@raisedadead raisedadead removed the status: blocked In a transient & temporary hold. label Jan 12, 2018
@raisedadead raisedadead added the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label Jan 12, 2018
@raisedadead
Copy link
Copy Markdown
Member

@QuincyLarson thanks to @scissorsneedfoodtoo I have updated @AungMyoKyaw 's pull request to address the error in the tests.

/cc @BerkeleyTrue I had to add a check here in the test entry point https://github.com/freeCodeCamp/freeCodeCamp/pull/15856/files#diff-fa70e80f212af821d2f311eb03e2ad60R218

Seems, there is sneaky exception thrown without it.

@scissorsneedfoodtoo
Copy link
Copy Markdown
Contributor

@raisedadead, thank you for updating @AungMyoKyaw's PR! I'm sorry I didn't do it sooner.

Everything LGTM! No exceptions or errors thrown anymore.

@QuincyLarson
Copy link
Copy Markdown
Contributor

@scissorsneedfoodtoo Awesome - thanks!

@raisedadead so we're just waiting for @BerkeleyTrue's approval of your change before we can merge this? https://github.com/freeCodeCamp/freeCodeCamp/pull/15856/files#diff-fa70e80f212af821d2f311eb03e2ad60R218

@raisedadead
Copy link
Copy Markdown
Member

Yes. That is correct @QuincyLarson

@BerkeleyTrue BerkeleyTrue merged commit a2d3cc6 into freeCodeCamp:staging Jan 16, 2018
@BerkeleyTrue BerkeleyTrue removed the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label Jan 16, 2018
@scissorsneedfoodtoo
Copy link
Copy Markdown
Contributor

@AungMyoKyaw, thank you! Glad we could get your contribution merged.

ValeraS pushed a commit to ValeraS/freeCodeCamp that referenced this pull request Oct 12, 2018
feat(euler-problem): Add tests and solution for Problem 4: Largest palindrome product
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants