Skip to content

Pass all tests except for the special character requirement test #14

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Mvrcusj
Copy link

@Mvrcusj Mvrcusj commented Jul 7, 2020

No description provided.

@DDiggs0798 DDiggs0798 closed this Jul 8, 2020
@johnny-rice
Copy link
Member

@DDiggs0798 we will want to approve reviews before closing to differentiate why something is closed.

We should also always add a comment about why a review is closed if it not approved so it can be clear to the student and also any TAs that will see it later.

@johnny-rice johnny-rice reopened this Jul 9, 2020
/* eslint-disable nonblock-statement-body-position */
Copy link
Member

Choose a reason for hiding this comment

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

This solution is very close to the solution @erick-pacheco has. Did you guys work together on this work?

index.js Outdated
// Using ASCII index and charCodeAt method (thanks to Jkearns!)
// Test further requirements
// Test for uppercase characters
Copy link
Member

Choose a reason for hiding this comment

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

Given a password of 10 chars, we will loop 10 times from this outer loop.

@DDiggs0798
Copy link

DDiggs0798 commented Jul 9, 2020 via email

index.js Outdated
for (let i = 0; i < password.length; i++) {
if (password.charCodeAt(i) >= 97 && password.charCodeAt(i) <= 122)
// Test for numeric value
Copy link
Member

Choose a reason for hiding this comment

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

Given a password of 10 chars, we will loop 10 times x 10 x 10 in this deeply nested inner loop.

We are now looping 1000 times. We are looping the same loop within itself.

Copy link
Member

@johnny-rice johnny-rice left a comment

Choose a reason for hiding this comment

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

Nice work. Too much looping is occurring as noted in the review comments. We can get this down to a single for loop.

index.js Outdated
if (password.charCodeAt(i) >= 48 && password.charCodeAt(i) <= 57)
// Test for special characters
for (let i = 0; i < password.length; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

Given a password of 10 chars, we will loop 10 times x 10 x 10 x 10 in this most deeply nested inner loop.

We are now looping 10,000 times. We are looping the same loop within itself.

Way more looping than needed. We can fix this so it loops only in the outer loop. 10x is all that the loop should need to run. There is an extra 9,990 loops happening here.

@Mvrcusj
Copy link
Author

Mvrcusj commented Jul 9, 2020 via email

/* eslint-disable nonblock-statement-body-position */
function validatePassword(password) {
Copy link
Member

Choose a reason for hiding this comment

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

Formatting is a bit tough to read.

In VS Code, you can use the formatter. Menu > View > Command Palette. Type in "Format document"

function validatePassword(password) {
  let requirementsMet = true

  // Determine if the password length is more than or equal to 8 then..
  if (password.length >= 8) {
    requirementsMet = true
    // Using ASCII index and charCodeAt method (thanks to Jkearns!)
  } else {
    requirementsMet = false
  }
  // Test further requirements
  // Test for uppercase characters
  for (let i = 0; i < password.length; i++) {
    if (password.charCodeAt(i) >= 65 && password.charCodeAt(i) <= 90) {
      requirementsMet = true
      // Test for lowercase characters
    } else {
      requirementsMet = false
    }
    if (password.charCodeAt(i) >= 97 && password.charCodeAt(i) <= 122) {
      requirementsMet = true
      // Test for numeric value
    } else {
      requirementsMet = false
    }
    if (password.charCodeAt(i) >= 48 && password.charCodeAt(i) <= 57) {
      requirementsMet = true
      // Test for special characters
    } else {
      requirementsMet = false
    }
    if (password.charCodeAt(i) >= 33 && password.charCodeAt(i) <= 47) {
      requirementsMet = true
    } else {
      requirementsMet = false
    }
    requirementsMet = true

    requirementsMet = false
  }

  return requirementsMet
}

module.exports = validatePassword

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.

3 participants