-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3765 from nyette/WV-96
Fixed a bug that prevents client-side data from clearing after the user requests data deletion
- Loading branch information
Showing
5 changed files
with
74 additions
and
44 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable max-classes-per-file */ | ||
|
||
class LinkedListNode { | ||
constructor (data, next = null) { | ||
this.data = data; | ||
this.next = next; | ||
} | ||
} | ||
|
||
const isValid = (input) => { | ||
// Check type | ||
const isArray = input instanceof Array; | ||
if (!isArray) throw new TypeError('Please enter an array.'); | ||
// Check length | ||
const isLongEnough = input.length > 1; | ||
if (!isLongEnough) throw new Error('Please enter an array a, such that a.length > 1.'); | ||
return true; | ||
}; | ||
|
||
export default class CircularLinkedList { | ||
constructor (input) { | ||
if (isValid(input)) { | ||
const dummy = new LinkedListNode(null); | ||
let tail = dummy; | ||
for (let i = 0; i < input.length; i++) { | ||
const element = input.at(i); | ||
tail.next = new LinkedListNode(element); | ||
tail = tail.next; | ||
} | ||
const head = dummy.next; | ||
tail.next = head; | ||
this.head = head; | ||
} | ||
} | ||
} |