Skip to content

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

Open
Mvrcusj wants to merge 3 commits into
SummerOfCode2020:masterfrom
Mvrcusj:answer
Open

Pass all tests except for the special character requirement test#14
Mvrcusj wants to merge 3 commits into
SummerOfCode2020:masterfrom
Mvrcusj:answer

Conversation

@Mvrcusj
Copy link
Copy Markdown

@Mvrcusj Mvrcusj commented Jul 7, 2020

No description provided.

@DDiggs0798 DDiggs0798 closed this Jul 8, 2020
@johnny-rice
Copy link
Copy Markdown
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
Comment thread index.js
@@ -1 +1,31 @@
// Do work! No newline at end of file
/* eslint-disable nonblock-statement-body-position */
Copy link
Copy Markdown
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?

Comment thread index.js Outdated
if (password.length >= 8) {
// Using ASCII index and charCodeAt method (thanks to Jkearns!)
// Test further requirements
// Test for uppercase characters
Copy link
Copy Markdown
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.

Comment thread index.js
@DDiggs0798
Copy link
Copy Markdown

DDiggs0798 commented Jul 9, 2020 via email

Comment thread index.js Outdated
// Test for lowercase characters
for (let i = 0; i < password.length; i++) {
if (password.charCodeAt(i) >= 97 && password.charCodeAt(i) <= 122)
// Test for numeric value
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread index.js Outdated
for (let i = 0; i < password.length; i++) {
if (password.charCodeAt(i) >= 48 && password.charCodeAt(i) <= 57)
// Test for special characters
for (let i = 0; i < password.length; i++) {
Copy link
Copy Markdown
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
Copy Markdown
Author

Mvrcusj commented Jul 9, 2020 via email

Comment thread index.js
@@ -1 +1,36 @@
// Do work! No newline at end of file
/* eslint-disable nonblock-statement-body-position */
function validatePassword(password) {
Copy link
Copy Markdown
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