Created
September 24, 2019 05:14
-
-
Save Shaddyjr/a4bd95fb06cd80c7da7118ca2c0f3d12 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Node{ | |
constructor(val){ | |
this.val = val | |
this.next = null; | |
} | |
} | |
function listContains(root, val){ | |
let curr = root; | |
while(curr){ | |
if(curr.val == val) return true; | |
curr = curr.next; | |
} | |
return false; | |
} | |
const Amy = new Node("Amy"); | |
const Barry = new Node("Barry"); | |
const Cameron = new Node("Cameron"); | |
Amy.next = Barry; | |
Barry.next = Cameron; | |
console.log(listContains(Amy, "Cameron")); // true | |
console.log(listContains(Amy, "Jenny")); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment