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
Show hidden characters
{ | |
"Print with labels": { | |
"scope": "javascript,typescript,javascriptreact,typescriptreact", | |
"prefix": "console-log-labeled", | |
"body": [ | |
"// TODO: Don't forget to delete this", | |
"console.log('\\x1b[35m\\x1b[1m\\x1b[42m%s\\x1b[0m', '################## ${1:LABEL} ##################');", | |
"console.log($2);", | |
"console.log('\\x1b[35m\\x1b[1m\\x1b[42m%s\\x1b[0m', '################ END $1 ################');", | |
], |
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(arr, num) { | |
arr.push(num); | |
arr = arr.sort(function(a, b) { return a - b; }); | |
return arr.indexOf(num); | |
} | |
// Tests | |
console.log(where([10, 20, 30, 40, 50], 35) + " should be 3"); | |
console.log(where([10, 20, 30, 40, 50], 30) + " should be 2"); | |
console.log(where([40, 60], 50) + " should be 1"); |
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 **/ |
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
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
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 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
//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 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
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; |
NewerOlder