Skip to content

Instantly share code, notes, and snippets.

View ArielLeslie's full-sized avatar
👻

Ariel ArielLeslie

👻
View GitHub Profile
@ArielLeslie
ArielLeslie / seek_and_destroy.js
Created October 6, 2015 17:30
Seek and Destroy
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;
@ArielLeslie
ArielLeslie / arguments_optional.js
Created October 6, 2015 17:32
Arguments Optional
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;
@ArielLeslie
ArielLeslie / diff_two_arrays.js
Created October 6, 2015 17:33
Diff Two Arrays
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;
@ArielLeslie
ArielLeslie / where_art_thou.js
Created October 6, 2015 17:34
Where Art Thou
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;
}
}
@ArielLeslie
ArielLeslie / make_properties_private.js
Created October 6, 2015 17:34
Make Properties Private
//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);
};
};
@ArielLeslie
ArielLeslie / mutations.js
Created October 13, 2015 16:20
Mutatations
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;
}
@ArielLeslie
ArielLeslie / dna_pairing.js
Created October 22, 2015 19:55
Bonfire: DNA Pairing
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)]]);
}
@ArielLeslie
ArielLeslie / convert_html.js
Created November 16, 2015 00:22
Bonfire: Convert HTML Entities
function convert(str) {
var mapping = {
'&' : '&amp;',
':' : '&colon;',
'<' : '&lt;',
'>' : '&gt;',
'"' : '&quot;',
"'" : '&apos;'
};
var words =str.split('');
@ArielLeslie
ArielLeslie / grid.html
Created November 24, 2015 23:41
skeleton code for Waypoint: Use the Bootstrap Grid to Put Elements Side By Side
<link href="http://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, Monospace;
}
/** 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 **/