Skip to content

Instantly share code, notes, and snippets.

@Shaddyjr
Created September 24, 2019 05:14
Show Gist options
  • Save Shaddyjr/a4bd95fb06cd80c7da7118ca2c0f3d12 to your computer and use it in GitHub Desktop.
Save Shaddyjr/a4bd95fb06cd80c7da7118ca2c0f3d12 to your computer and use it in GitHub Desktop.
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