Created
July 11, 2015 07:18
-
-
Save anonymous/6b230f7bb938f8f2dc62 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/sumoqu
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="underbar: contains" content="underbar: contains"> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var nums = [1, 2, 3]; | |
var person = { | |
name: 'John' | |
}; | |
function contains(element, collection) { | |
if(Array.isArray(collection)){ | |
var index = collection.indexOf(element); | |
if (index !== -1) { | |
return true; | |
} else { | |
return false; | |
} | |
} else { | |
return collection ? hasOwnProperty.call(collection, element) : false; | |
} | |
} | |
console.log(contains(3, nums)); | |
console.log(contains(4, nums)); | |
console.log(contains('name', person)); | |
console.log(contains('wat', person)); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var nums = [1, 2, 3]; | |
var person = { | |
name: 'John' | |
}; | |
function contains(element, collection) { | |
if(Array.isArray(collection)){ | |
var index = collection.indexOf(element); | |
if (index !== -1) { | |
return true; | |
} else { | |
return false; | |
} | |
} else { | |
return collection ? hasOwnProperty.call(collection, element) : false; | |
} | |
} | |
console.log(contains(3, nums)); | |
console.log(contains(4, nums)); | |
console.log(contains('name', person)); | |
console.log(contains('wat', person));</script></body> | |
</html> |
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
var nums = [1, 2, 3]; | |
var person = { | |
name: 'John' | |
}; | |
function contains(element, collection) { | |
if(Array.isArray(collection)){ | |
var index = collection.indexOf(element); | |
if (index !== -1) { | |
return true; | |
} else { | |
return false; | |
} | |
} else { | |
return collection ? hasOwnProperty.call(collection, element) : false; | |
} | |
} | |
console.log(contains(3, nums)); | |
console.log(contains(4, nums)); | |
console.log(contains('name', person)); | |
console.log(contains('wat', person)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment