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
function destroyer(arr) { | |
var args = []; | |
for (i = 1; i < arguments.length; i++){ | |
args.push(arguments[i]); | |
} | |
return arr.filter(function(x){ | |
if (args.indexOf(x) >= 0) | |
return false; | |
else | |
return true; |
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
function add() { | |
var first = arguments[0]; | |
if (arguments.length == 1 && typeof first === "number"){ | |
return function(x){ | |
return add(first, x); | |
}; | |
}else if (arguments.length == 2 && typeof first === "number" && typeof arguments[1] === "number"){ | |
return first + arguments[1]; | |
}else{ | |
return undefined; |
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
function diff(arr1, arr2) { | |
//just add two two arrays together | |
var newArr = arr1.concat(arr2); | |
//then filter it | |
return newArr.filter(function(val){ | |
// return true if the value is not in one of the arrays | |
if (arr1.indexOf(val) < 0 || arr2.indexOf(val) < 0){ | |
return true; | |
}else{ | |
return false; |
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
function where(collection, source) { | |
var arr = []; | |
// What's in a name? | |
src_keys = Object.keys(source); | |
arr = collection.filter(function(i){ | |
for(j = 0; j < src_keys.length; j++){ | |
if(!i.hasOwnProperty(src_keys[j]) || i[src_keys[j]] !== source[src_keys[j]]){ | |
return false; | |
} | |
} |
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
//Let's create an object with a two functions. One attached as a property and one not. | |
var Car = function() { | |
this.gear = 1; | |
function addStyle(styleMe){ | |
return 'The Current Gear Is: ' + styleMe; | |
} | |
this.getGear = function() { | |
return addStyle(this.gear); | |
}; | |
}; |
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
function mutation(arr) { | |
arr[0] = arr[0].toLowerCase(); | |
arr[1] = arr[1].toLowerCase(); | |
for (i = 0; i < arr[1].length; i++){ | |
if(arr[0].indexOf(arr[1].charAt(i)) < 0){ | |
return false; | |
} | |
} | |
return true; | |
} |
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
function pair(str) { | |
var pairs = [['A', 'T'], ['C', 'G']]; | |
var myPairs = []; | |
for (i = 0; i < str.length; i++){ | |
for(j = 0; j < pairs.length; j++){ | |
var index = pairs[j].indexOf(str[i]); | |
if (index >= 0) { | |
myPairs.push([pairs[j][index], pairs[j][3%(index+2)]]); | |
} |
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
function convert(str) { | |
var mapping = { | |
'&' : '&', | |
':' : ':', | |
'<' : '<', | |
'>' : '>', | |
'"' : '"', | |
"'" : ''' | |
}; | |
var words =str.split(''); |
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
<link href="http://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css"> | |
<style> | |
.red-text { | |
color: red; | |
} | |
h2 { | |
font-family: Lobster, Monospace; | |
} |
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
/** R T & F A V T W I T T E R B O T **/ | |
/** ======================================= **/ | |
/** Written by Amit Agarwal @labnol on 31/07/2015 **/ | |
/** Tutorial link: http://www.labnol.org/?p=28967 **/ |
OlderNewer