Frage im Vorstellungsgespräch bei Netflix

Write a contains function in javascript

Antworten zu Vorstellungsgespräch

Anonym

13. Sep. 2014

HTMLElement.prototype.contains = HTMLElement.prototype.contains || function(child) { var children; var i; var node; if (this == child) { return true; } if (this.hasChildNodes) { for (i = 0, children = this.childNodes; i < children.length; i++) { node = children[i]; // skip for text nodes if (node.nodeType === 1 && (node == child || node.contains(child))) { return true; } } } return false; };

2

Anonym

2. Aug. 2015

function contains(needle, haystack) { var a = needle, b = haystack, result; return result = b.indexOf(a) !== -1 ? true : false; }

Anonym

22. Juli 2012

function checkContains() { var url = "this is the answer"; if(url.indexOf("answer")!=-1) alert("contains"); else alert("not contains"); }