Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(challenge): Prevent use of String.repeat() in Basic Algorithm #12930

Merged
merged 1 commit into from
Jan 28, 2017
Merged

fix(challenge): Prevent use of String.repeat() in Basic Algorithm #12930

merged 1 commit into from
Jan 28, 2017

Conversation

Greenheart
Copy link
Member

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:

Description

Since algorithm challenges aim to help campers practice creating algorithms, we recommended their own solutions over those built into the language. This PR adds a test that prevent the most straight-forward forms of cheating by using String.repeat().

It won't catch all possible ways, but it's better than nothing.

@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 Jan 28, 2017
Copy link
Member

@systimotic systimotic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if we ever decided whether to use regex.test(code) or code.match(regex). Not a dealbreaker for this PR though, I think.

Thanks for picking up this ancient issue!

@@ -392,7 +392,8 @@
"assert(repeatStringNumTimes(\"abc\", 4) === \"abcabcabcabc\", 'message: <code>repeatStringNumTimes(\"abc\", 4)</code> should return <code>\"abcabcabcabc\"</code>.');",
"assert(repeatStringNumTimes(\"abc\", 1) === \"abc\", 'message: <code>repeatStringNumTimes(\"abc\", 1)</code> should return <code>\"abc\"</code>.');",
"assert(repeatStringNumTimes(\"*\", 8) === \"********\", 'message: <code>repeatStringNumTimes(\"*\", 8)</code> should return <code>\"********\"</code>.');",
"assert(repeatStringNumTimes(\"abc\", -2) === \"\", 'message: <code>repeatStringNumTimes(\"abc\", -2)</code> should return <code>\"\"</code>.');"
"assert(repeatStringNumTimes(\"abc\", -2) === \"\", 'message: <code>repeatStringNumTimes(\"abc\", -2)</code> should return <code>\"\"</code>.');",
"assert(!/[.]repeat/g.test(code), 'message: The built-in <code>repeat()</code>-method should not be used');"

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@Greenheart
Copy link
Member Author

@systimotic Thanks for the feedback, and pointing me to this issue!

I did a quick check and it seems like there's an even distribution between the two methods. I prefer RegExp.test() since it's returning a boolean and we don't really need the actual matching strings when writing simple assertions 😊

Copy link
Member

@systimotic systimotic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Thanks @Greenheart!

@systimotic systimotic merged commit fbe86aa into freeCodeCamp:staging Jan 28, 2017
@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 28, 2017
@Greenheart Greenheart deleted the fix/basic-algorithm-prevent-use-of-string-repeat branch January 28, 2017 21:45
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.

None yet

3 participants