> For the complete documentation index, see [llms.txt](https://edsonha.gitbook.io/my-gitbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://edsonha.gitbook.io/my-gitbook/refactoring/code-smells/duplicate-code.md).

# Duplicate Code

```javascript
//Problem:
class MedicalRecord {
  constructor() {
    this.dDateArchived = null;
    this.bArchived = false;
  }

  archiveRecord() {
    this.bArchived = true;
    this.dDateArchived = Date.now();
  }

  closeRecord() {
    this.bArchived = true;
    this.dDateArchived = Date.now();
  }
}


//**Solution**:
class MedicalRecord {
  constructor() {
    this.dDateArchived = null;
    this.bArchived = false;
  }

  archiveRecord() {
    this._switchToArchived();
  }

  closeRecord() {
    this._switchToArchived();
  }

  _switchToArchived() {
    this.bArchived = true;
    this.dDateArchived = Date.now();
  }
}
```
