acmcsufoss / lc-dailies

Daily Leetcode challenges for members to practice their algorithms.
https://acmcsuf.com/lc-dailies
MIT License
3 stars 0 forks source link

Refactor `parseSubmissionID` #18

Closed karnikaavelumani closed 1 year ago

karnikaavelumani commented 1 year ago

Members should be able to submit the code using any for the URL containing the appropriate ID. For example, the following URL (https:// leetcode.com/problems/unique-paths/submissions/1039832006/?envType=daily-question&envId=2023-09-03) should satisfy the submission instead of providing an error.

Refactor the following:

/**
 * parseSubmissionID parses the submission ID from the submission URL.
 */
export function parseSubmissionID(submissionURLOrID: string): string {
  if (LEETCODE_SUBMISSIONS_URL_PATTERN.test(submissionURLOrID)) {
    return submissionURLOrID.replace(LEETCODE_SUBMISSIONS_URL_PATTERN, "")
      .replace(/\/$/, "");
  }

  return submissionURLOrID;
}

const LEETCODE_SUBMISSIONS_URL_PATTERN =
  /^https:\/\/leetcode\.com\/(problems\/.*\/submissions\/|submissions\/detail\/)/;

Note: Keep in mind if the Handbook MD must be edited

karnikaavelumani commented 1 year ago

Warning This feature will require unit testing.

EthanThatOneKid commented 1 year ago

Resolved in #25.