Skip to content

Instantly share code, notes, and snippets.

@Masd925
Last active April 6, 2017 10:46
Show Gist options
  • Select an option

  • Save Masd925/8b1a9b1d37c322827dcd to your computer and use it in GitHub Desktop.

Select an option

Save Masd925/8b1a9b1d37c322827dcd to your computer and use it in GitHub Desktop.

Revisions

  1. Masd925 revised this gist Mar 30, 2017. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions #Some FCC one-liner solutions
    Original file line number Diff line number Diff line change
    @@ -1,3 +1 @@
    Some FCC one-liner solutions

    One-liners on Exact change, Inventory update, Smallest common multiple, and Sum all fibonacci numbers, are not good enough to be shown here.
    Some FCC one-liner solutions
  2. Masd925 revised this gist Mar 30, 2017. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions Smallest common multiple.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    function smallestCommons(arr) {
    return arguments.length===1 ?
    Array.apply(null, {length: Math.max(arr[0],arr[1])-Math.min(arr[0],arr[1])+1})
    .map(function(value, index){
    return Math.min(arr[0],arr[1]) + index;
    })
    .reduce(function(prev,curr){return prev*curr / smallestCommons(prev,curr);})
    :
    arguments[1]===0 ? arguments[0] : smallestCommons(arguments[1], arguments[0]%arguments[1]);
    }
  3. Masd925 revised this gist Mar 30, 2017. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions Inventory update.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    function updateInventory(old, del) {
    return del.reduce(function(prev,curr){
    return ((ind = (itemNames = old.reduce(function(prev,curr){
    return prev.concat(curr[1]);
    },[])).indexOf(curr[1]))===-1) ?
    itemNames.push(curr[1])&&prev.concat([curr])
    :
    (prev[ind][0] += curr[0])&&prev;
    },old).sort(function(a,b){
    return a[1]===b[1] ? 0 :
    a[1] < b[1] ? -1 : 1;
    });
    }
  4. Masd925 revised this gist Mar 30, 2017. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions Exact change.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    function checkCashRegister(price, cash, cid) {
    return (changeLeft = cash-price) && (change = cid.reverse().reduce(function(prev,curr){
    return (amount = (Math.min(changeLeft,curr[1])+(LAMBDA=0.0000001))/
    (note = {"ONE HUNDRED":100,"TWENTY":20,"TEN":10,"FIVE":5,"ONE":1,"QUARTER":0.25,
    "DIME":0.10,"NICKEL":0.05,"PENNY":0.01}[curr[0]])>>0) ?
    prev.push([curr[0],amount*note]) && (curr[1] -= amount*note)+1 && (changeLeft -= amount*note)+1 && prev
    :
    prev;
    },[])) &&
    changeLeft>LAMBDA ?
    "Insufficient Funds"
    :
    cid.every(function(elem){return elem[1]<LAMBDA;}) ? "Closed" : change;
    }
  5. Masd925 revised this gist Sep 16, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Counting cards.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    function cc(card) {
    return (count+={2:1,3:1,4:1,5:1,6:1,7:0,8:0,9:0,10:-1,J:-1,Q:-1,K:-1,A:-1}[card]) + " " + (count>0 ? "Bet" : "Hold");
    return (count+={2:1,3:1,4:1,5:1,6:1,7:0,8:0,9:0,10:-1,J:-1,Q:-1,K:-1,A:-1}[card]) + (count>0 ? " Bet" : " Hold");
    }
  6. Masd925 revised this gist Aug 19, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Steamroller.js
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    function steamrollArray(arr) {
    function steamrollArray(arr) { // recursive
    return Array.isArray(arr) ? Array.prototype.concat.apply([],arr.map(steamrollArray)):arr;
    }

    function steamrollArray(arr) {
    function steamrollArray(arr) { // non-recursive
    while (arr.some(Array.isArray)) {
    arr = Array.prototype.concat.apply([],arr);
    }
  7. Masd925 revised this gist Aug 19, 2016. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions Steamroller.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    function steamroller(arr) {
    return arr.length ? (Array.isArray(arr[0]) ? steamroller(arr.shift()) : [arr.shift()]).concat(steamroller(arr)) : [];
    function steamrollArray(arr) {
    return Array.isArray(arr) ? Array.prototype.concat.apply([],arr.map(steamrollArray)):arr;
    }

    function steamrollArray(arr) {
    while (arr.some(Array.isArray)) {
    arr = Array.prototype.concat.apply([],arr);
    }
    return arr;
    }
  8. Masd925 revised this gist Apr 21, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion #Some FCC one-liner solutions
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    Some FCC one-liner solutions

    One-liners on Exact change, Inventory update, and Sum all fibonacci numbers, are not good enough to be shown here.
    One-liners on Exact change, Inventory update, Smallest common multiple, and Sum all fibonacci numbers, are not good enough to be shown here.
  9. Masd925 revised this gist Apr 8, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Mutations.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    function mutation(arr) {
    return arr[1].toLowerCase().split("").every(function(val, index, array){
    return arr[1].toLowerCase().split("").every(function(val){
    return arr[0].toLowerCase().indexOf(val)>-1;
    });
    }
  10. Masd925 revised this gist Mar 31, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion #Some FCC one-liner solutions
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    Some FCC one-liner solutions

    One-liners on Exact change and Inventory update are not good enough to be shown here.
    One-liners on Exact change, Inventory update, and Sum all fibonacci numbers, are not good enough to be shown here.
  11. Masd925 revised this gist Mar 8, 2016. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion #Some FCC one-liner solutions
    Original file line number Diff line number Diff line change
    @@ -1 +1,3 @@
    Some FCC one-liner solutions
    Some FCC one-liner solutions

    One-liners on Exact change and Inventory update are not good enough to be shown here.
  12. Masd925 revised this gist Mar 8, 2016. 2 changed files with 0 additions and 30 deletions.
    17 changes: 0 additions & 17 deletions Exact change
    Original file line number Diff line number Diff line change
    @@ -1,17 +0,0 @@
    function drawer(price, cash, cid) {
    return (changeLeft = cash-price) &&

    (change = cid.reverse().reduce(function(prev,curr){
    return (amount = (Math.min(changeLeft,curr[1])+(LAMBDA=0.0000001))/
    (note = {"ONE HUNDRED":100,"TWENTY":20,"TEN":10,"FIVE":5,"ONE":1,"QUARTER":0.25,
    "DIME":0.10,"NICKEL":0.05,"PENNY":0.01}[curr[0]])>>0) ?
    prev.push([curr[0],amount*note]) && (curr[1] -= amount*note)+1 && (changeLeft -= amount*note)+1 && prev
    :
    prev;
    },[])) &&

    changeLeft>LAMBDA ?
    "Insufficient Funds"
    :
    cid.every(function(elem){return elem[1]<LAMBDA;}) ? "Closed" : change;
    }
    13 changes: 0 additions & 13 deletions Inventory update
    Original file line number Diff line number Diff line change
    @@ -1,13 +0,0 @@
    function inventory(old, del) {
    return del.reduce(function(prev,curr){
    return ((ind = (itemNames = old.reduce(function(prev,curr){
    return prev.concat(curr[1]);
    },[])).indexOf(curr[1]))===-1) ?
    itemNames.push(curr[1])&&prev.concat([curr])
    :
    (prev[ind][0] += curr[0])&&prev;
    },old).sort(function(a,b){
    return a[1]===b[1] ? 0 :
    a[1] < b[1] ? -1 : 1;
    });
    }
  13. Masd925 revised this gist Mar 7, 2016. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions Exact change
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    function drawer(price, cash, cid) {
    return (changeLeft = cash-price) &&

    (change = cid.reverse().reduce(function(prev,curr){
    return (amount = (Math.min(changeLeft,curr[1])+(LAMBDA=0.0000001))/
    (note = {"ONE HUNDRED":100,"TWENTY":20,"TEN":10,"FIVE":5,"ONE":1,"QUARTER":0.25,
    "DIME":0.10,"NICKEL":0.05,"PENNY":0.01}[curr[0]])>>0) ?
    prev.push([curr[0],amount*note]) && (curr[1] -= amount*note)+1 && (changeLeft -= amount*note)+1 && prev
    :
    prev;
    },[])) &&

    changeLeft>LAMBDA ?
    "Insufficient Funds"
    :
    cid.every(function(elem){return elem[1]<LAMBDA;}) ? "Closed" : change;
    }
  14. Masd925 revised this gist Mar 7, 2016. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions Inventory update
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    function inventory(old, del) {
    return del.reduce(function(prev,curr){
    return ((ind = (itemNames = old.reduce(function(prev,curr){
    return prev.concat(curr[1]);
    },[])).indexOf(curr[1]))===-1) ?
    itemNames.push(curr[1])&&prev.concat([curr])
    :
    (prev[ind][0] += curr[0])&&prev;
    },old).sort(function(a,b){
    return a[1]===b[1] ? 0 :
    a[1] < b[1] ? -1 : 1;
    });
    }
  15. Masd925 revised this gist Mar 7, 2016. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions Profile lookup.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    function lookUp(firstName, prop){
    return contacts.reduce(function(prev,curr){
    return curr.firstName===firstName ?
    curr.hasOwnProperty(prop) ? curr[prop] : "No such property"
    :
    prev;
    },"No such contact");
    }
  16. Masd925 revised this gist Mar 4, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Reverse a string.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    function reverseString(str) {
    return str.length ? reverseString(str.substring(1))+str.charAt(0) : "";
    return str.length ? reverseString(str.slice(1))+str.charAt(0) : "";
    }
  17. Masd925 revised this gist Mar 4, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Caesars Cipher.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    function rot13(str) {
    return str.split("").map(function(char){
    return (char.charCodeAt(0)>64 && char.charCodeAt(0)<91) ? String.fromCharCode(char.charCodeAt(0)%26+65) : char;
    return ((cc=char.charCodeAt(0))>64 && cc<91) ? String.fromCharCode(cc%26+65) : char;
    }).join("");
    }
  18. Masd925 revised this gist Mar 2, 2016. 30 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
  19. Masd925 revised this gist Mar 2, 2016. 5 changed files with 26 additions and 38 deletions.
    38 changes: 0 additions & 38 deletions Binary agents
    Original file line number Diff line number Diff line change
    @@ -3,41 +3,3 @@ function binaryAgent(str) {
    return String.fromCharCode(parseInt(elem,2));
    }).join("");
    }

    ----Symmetric difference----

    function sym(args) {
    return Array.prototype.slice.call(arguments).reduce(function(prev, curr){
    return prev.concat(curr.filter(function(val, index){
    return curr.indexOf(val)===index;
    })).filter(function(val,ind,array){
    return array.indexOf(val)===array.lastIndexOf(val);
    });
    }, []);
    }

    ----Title case a sentence----

    function titleCase(str) {
    return str.split(' ').map(function(val){
    return val.charAt(0).toUpperCase() + val.substr(1).toLowerCase();
    }).join(' ');
    }

    ----Where art thou----

    function where(collection, source) {
    return collection.filter(function(obj){
    return Object.keys(source).every(function(key){
    return obj[key]===source[key];
    });
    });
    }

    ----Where do I belong----

    function where(arr, num) {
    return arr.reduce(function(prev, curr){
    return curr<num ? prev+1 : prev;
    },0);
    }
    9 changes: 9 additions & 0 deletions Symmetric difference
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    function sym(args) {
    return Array.prototype.slice.call(arguments).reduce(function(prev, curr){
    return prev.concat(curr.filter(function(val, index){
    return curr.indexOf(val)===index;
    })).filter(function(val,ind,array){
    return array.indexOf(val)===array.lastIndexOf(val);
    });
    }, []);
    }
    5 changes: 5 additions & 0 deletions Title case a sentence
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    function titleCase(str) {
    return str.split(' ').map(function(val){
    return val.charAt(0).toUpperCase() + val.substr(1).toLowerCase();
    }).join(' ');
    }
    7 changes: 7 additions & 0 deletions Where art thou
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    function where(collection, source) {
    return collection.filter(function(obj){
    return Object.keys(source).every(function(key){
    return obj[key]===source[key];
    });
    });
    }
    5 changes: 5 additions & 0 deletions Where do I belong
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    function where(arr, num) {
    return arr.reduce(function(prev, curr){
    return curr<num ? prev+1 : prev;
    },0);
    }
  20. Masd925 revised this gist Mar 2, 2016. 7 changed files with 36 additions and 54 deletions.
    54 changes: 0 additions & 54 deletions Binary agents
    Original file line number Diff line number Diff line change
    @@ -4,60 +4,6 @@ function binaryAgent(str) {
    }).join("");
    }

    ----Reverse a string----

    function reverseString(str) {
    return str.length ? reverseString(str.substring(1))+str.charAt(0) : "";
    }

    ----Roman numeral converter----

    function convert(num) {
    return Array.prototype.reduce.call(num.toString(),function(prev,curr,index,array){
    return prev.concat([[0],[1],[1,1],[1,1,1],[1,5],[5],[5,1],[5,1,1],[5,1,1,1],[1,10]][curr].map(function(elem){
    return elem*Math.pow(10,array.length-1-index);
    }));
    },[]).map(function(elem){
    return ['M', 'D', 'C', 'L', 'X', 'V', 'I'][[1000,500,100,50,10,5,1].indexOf(elem)];
    }).join("");
    }

    ----Seek and destroy----

    function destroyer(arr) {
    return arr.filter(function(val) {
    return Array.prototype.indexOf.call(this,val,1)===-1;
    },arguments);
    }

    ----Sorted union----

    function unite(arr1, arr2, arr3) {
    return Array.prototype.reduce.call(arguments, function(prev,curr){
    return prev.concat(curr).filter(function(val, index, array){
    return array.indexOf(val)===index;
    });
    });
    }

    ----Steamroller----

    function steamroller(arr) {
    return arr.length ? (Array.isArray(arr[0]) ? steamroller(arr.shift()) : [arr.shift()]).concat(steamroller(arr)) : [];
    }

    ----Sum all primes----

    function sumPrimes(num) {
    return arguments.length!==1 ?
    num>1 ?
    sumPrimes(num-1, arguments[1].filter(function(val){return val%num!==0;}).concat(num))
    :
    arguments[1].reduce(function(a,b){return a+b;})
    :
    num>1 ? sumPrimes(num-1, [num]) : 0;
    }

    ----Symmetric difference----

    function sym(args) {
    3 changes: 3 additions & 0 deletions Reverse a string
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    function reverseString(str) {
    return str.length ? reverseString(str.substring(1))+str.charAt(0) : "";
    }
    9 changes: 9 additions & 0 deletions Roman numeral converter
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    function convert(num) {
    return Array.prototype.reduce.call(num.toString(),function(prev,curr,index,array){
    return prev.concat([[0],[1],[1,1],[1,1,1],[1,5],[5],[5,1],[5,1,1],[5,1,1,1],[1,10]][curr].map(function(elem){
    return elem*Math.pow(10,array.length-1-index);
    }));
    },[]).map(function(elem){
    return ['M', 'D', 'C', 'L', 'X', 'V', 'I'][[1000,500,100,50,10,5,1].indexOf(elem)];
    }).join("");
    }
    5 changes: 5 additions & 0 deletions Seek and destroy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    function destroyer(arr) {
    return arr.filter(function(val) {
    return Array.prototype.indexOf.call(this,val,1)===-1;
    },arguments);
    }
    7 changes: 7 additions & 0 deletions Sorted union
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    function unite(arr1, arr2, arr3) {
    return Array.prototype.reduce.call(arguments, function(prev,curr){
    return prev.concat(curr).filter(function(val, index, array){
    return array.indexOf(val)===index;
    });
    });
    }
    3 changes: 3 additions & 0 deletions Steamroller
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    function steamroller(arr) {
    return arr.length ? (Array.isArray(arr[0]) ? steamroller(arr.shift()) : [arr.shift()]).concat(steamroller(arr)) : [];
    }
    9 changes: 9 additions & 0 deletions Sum all primes
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    function sumPrimes(num) {
    return arguments.length!==1 ?
    num>1 ?
    sumPrimes(num-1, arguments[1].filter(function(val){return val%num!==0;}).concat(num))
    :
    arguments[1].reduce(function(a,b){return a+b;})
    :
    num>1 ? sumPrimes(num-1, [num]) : 0;
    }
  21. Masd925 revised this gist Mar 2, 2016. 5 changed files with 21 additions and 33 deletions.
    33 changes: 0 additions & 33 deletions Binary agents
    Original file line number Diff line number Diff line change
    @@ -4,39 +4,6 @@ function binaryAgent(str) {
    }).join("");
    }

    ----Mutations----

    function mutation(arr) {
    return arr[1].toLowerCase().split("").every(function(val, index, array){
    return arr[0].toLowerCase().indexOf(val)>-1;
    });
    }

    ----Pairwise----

    function pairwise(arr, arg) {
    return arr.reduce(function(prev,curr,index){
    arr.forEach(function(elem,ind){
    if (ind>index && curr+elem===arg && prev.indexOf(index)===-1 && prev.indexOf(ind)===-1) prev.push(index,ind);
    });
    return prev;
    },[]).reduce(function(cur,pre){return cur+pre;},0);
    }

    ----Repeat a string----

    function repeat(str, num) {
    return num>0 ? str+repeat(str,num-1) : "";
    }

    ----Return largest numbers in arrays----

    function largestOfFour(arr) {
    return arr.map(function(innerArray){
    return Math.max.apply(null,innerArray);
    });
    }

    ----Reverse a string----

    function reverseString(str) {
    5 changes: 5 additions & 0 deletions Mutations
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    function mutation(arr) {
    return arr[1].toLowerCase().split("").every(function(val, index, array){
    return arr[0].toLowerCase().indexOf(val)>-1;
    });
    }
    8 changes: 8 additions & 0 deletions Pairwise
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    function pairwise(arr, arg) {
    return arr.reduce(function(prev,curr,index){
    arr.forEach(function(elem,ind){
    if (ind>index && curr+elem===arg && prev.indexOf(index)===-1 && prev.indexOf(ind)===-1) prev.push(index,ind);
    });
    return prev;
    },[]).reduce(function(cur,pre){return cur+pre;},0);
    }
    3 changes: 3 additions & 0 deletions Repeat a string
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    function repeat(str, num) {
    return num>0 ? str+repeat(str,num-1) : "";
    }
    5 changes: 5 additions & 0 deletions Return largest numbers in arrays
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    function largestOfFour(arr) {
    return arr.map(function(innerArray){
    return Math.max.apply(null,innerArray);
    });
    }
  22. Masd925 revised this gist Mar 2, 2016. 4 changed files with 11 additions and 20 deletions.
    20 changes: 0 additions & 20 deletions Binary agents
    Original file line number Diff line number Diff line change
    @@ -4,26 +4,6 @@ function binaryAgent(str) {
    }).join("");
    }

    ----Finders keepers----

    function find(arr, func) {
    return arr.length ? (func(arr[0]) ? arr[0] : find(arr.slice(1),func)) : undefined;
    }

    ----Find the longest word in a string----

    function findLongestWord(str) {
    return str.split(' ').reduce(function(prev, curr) {
    return Math.max(prev, curr.length);
    }, 0);
    }

    ----Missing letters----

    function fearNotLetter(str) {
    if (str.length>1) return str.charCodeAt(1)===str.charCodeAt(0)+1 ? fearNotLetter(str.slice(1)) : String.fromCharCode(str.charCodeAt(0)+1);
    }

    ----Mutations----

    function mutation(arr) {
    5 changes: 5 additions & 0 deletions Find the longest word in a string
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    function findLongestWord(str) {
    return str.split(' ').reduce(function(prev, curr) {
    return Math.max(prev, curr.length);
    }, 0);
    }
    3 changes: 3 additions & 0 deletions Finders keepers
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    function find(arr, func) {
    return arr.length ? (func(arr[0]) ? arr[0] : find(arr.slice(1),func)) : undefined;
    }
    3 changes: 3 additions & 0 deletions Missing letters
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    function fearNotLetter(str) {
    if (str.length>1) return str.charCodeAt(1)===str.charCodeAt(0)+1 ? fearNotLetter(str.slice(1)) : String.fromCharCode(str.charCodeAt(0)+1);
    }
  23. Masd925 revised this gist Mar 2, 2016. 11 changed files with 11 additions and 20 deletions.
    20 changes: 0 additions & 20 deletions Binary agents.js → Binary agents
    Original file line number Diff line number Diff line change
    @@ -4,26 +4,6 @@ function binaryAgent(str) {
    }).join("");
    }

    ----Drop it----

    function drop(arr, func) {
    return (arr.length && !func(arr[0])) ? drop(arr.slice(1),func) : arr;
    }

    ----Everything be true----

    function every(collection, pre) {
    return collection.every(function(obj){
    return obj[pre];
    });
    }

    ----Falsy bouncer----

    function bouncer(arr) {
    return arr.filter(function(val){return val;});
    }

    ----Finders keepers----

    function find(arr, func) {
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    3 changes: 3 additions & 0 deletions Drop it
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    function drop(arr, func) {
    return (arr.length && !func(arr[0])) ? drop(arr.slice(1),func) : arr;
    }
    5 changes: 5 additions & 0 deletions Everything be true
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    function every(collection, pre) {
    return collection.every(function(obj){
    return obj[pre];
    });
    }
    3 changes: 3 additions & 0 deletions Falsy bouncer
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    function bouncer(arr) {
    return arr.filter(function(val){return val;});
    }
  24. Masd925 revised this gist Mar 2, 2016. 2 changed files with 6 additions and 5 deletions.
    6 changes: 1 addition & 5 deletions #Some FCC one-liner solutions
    Original file line number Diff line number Diff line change
    @@ -1,5 +1 @@
    function add() {
    return (arguments.length===2 && typeof(arguments[0])==='number' && typeof(arguments[1])==='number') ?
    arguments[0] + arguments[1] :
    (arguments.length===1 && typeof(arguments[0])==='number') ? add.bind(null, arguments[0]) : undefined;
    }
    Some FCC one-liner solutions
    5 changes: 5 additions & 0 deletions Arguments optional
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    function add() {
    return (arguments.length===2 && typeof(arguments[0])==='number' && typeof(arguments[1])==='number') ?
    arguments[0] + arguments[1] :
    (arguments.length===1 && typeof(arguments[0])==='number') ? add.bind(null, arguments[0]) : undefined;
    }
  25. Masd925 renamed this gist Mar 2, 2016. 1 changed file with 0 additions and 0 deletions.
  26. Masd925 renamed this gist Mar 2, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  27. Masd925 revised this gist Mar 2, 2016. 8 changed files with 29 additions and 58 deletions.
    58 changes: 0 additions & 58 deletions Binary agents.js
    Original file line number Diff line number Diff line change
    @@ -1,67 +1,9 @@
    ----Binary Agents----

    function binaryAgent(str) {
    return str.split(" ").map(function(elem){
    return String.fromCharCode(parseInt(elem,2));
    }).join("");
    }

    ----Boo who----

    function boo(bool) {
    return !!bool===bool;
    }

    ----Caesars Cipher----

    function rot13(str) {
    return str.split("").map(function(char){
    return (char.charCodeAt(0)>64 && char.charCodeAt(0)<91) ? String.fromCharCode(char.charCodeAt(0)%26+65) : char;
    }).join("");
    }

    ----Check for palindromes----

    function palindrome(str) {
    return str.replace(/[\W_]/g,"").toLowerCase().split("").every(function(elem,index,array){
    return elem===array[array.length-1-index];
    });
    }

    ----Chunky monkey----

    function chunk(arr, size) {
    return arr.length ? [arr.splice(0,size)].concat(chunk(arr,size)):[];
    }

    ----Confirm the ending----

    function end(str, target) {
    return str.slice(-target.length)===target;
    }

    ----Counting cards----

    function cc(card) {
    return (count+={2:1,3:1,4:1,5:1,6:1,7:0,8:0,9:0,10:-1,J:-1,Q:-1,K:-1,A:-1}[card]) + " " + (count>0 ? "Bet" : "Hold");
    }

    ----Diff two arrays----

    function diff(arr1, arr2) {
    return arr1.concat(arr2).filter(function(val, index, array){
    return array.indexOf(val)===array.lastIndexOf(val);
    });
    }

    ----DNA pairing----

    function pair(str){
    return Array.prototype.map.call(str, function(val){
    return [val,{A:'T', T: 'A', C: 'G', G: 'C'}[val]];
    });
    }

    ----Drop it----

    function drop(arr, func) {
    5 changes: 5 additions & 0 deletions Caesars Cipher.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    function rot13(str) {
    return str.split("").map(function(char){
    return (char.charCodeAt(0)>64 && char.charCodeAt(0)<91) ? String.fromCharCode(char.charCodeAt(0)%26+65) : char;
    }).join("");
    }
    5 changes: 5 additions & 0 deletions Check for palindromes.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    function palindrome(str) {
    return str.replace(/[\W_]/g,"").toLowerCase().split("").every(function(elem,index,array){
    return elem===array[array.length-1-index];
    });
    }
    3 changes: 3 additions & 0 deletions Chunky monkey.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    function chunk(arr, size) {
    return arr.length ? [arr.splice(0,size)].concat(chunk(arr,size)):[];
    }
    3 changes: 3 additions & 0 deletions Confirm the ending.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    function end(str, target) {
    return str.slice(-target.length)===target;
    }
    3 changes: 3 additions & 0 deletions Counting cards.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    function cc(card) {
    return (count+={2:1,3:1,4:1,5:1,6:1,7:0,8:0,9:0,10:-1,J:-1,Q:-1,K:-1,A:-1}[card]) + " " + (count>0 ? "Bet" : "Hold");
    }
    5 changes: 5 additions & 0 deletions DNA pairing
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    function pair(str){
    return Array.prototype.map.call(str, function(val){
    return [val,{A:'T', T: 'A', C: 'G', G: 'C'}[val]];
    });
    }
    5 changes: 5 additions & 0 deletions Diff two arrays.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    function diff(arr1, arr2) {
    return arr1.concat(arr2).filter(function(val, index, array){
    return array.indexOf(val)===array.lastIndexOf(val);
    });
    }
  28. Masd925 revised this gist Mar 2, 2016. 3 changed files with 3 additions and 10 deletions.
    File renamed without changes.
    10 changes: 0 additions & 10 deletions one-liners.txt → Binary agents.js
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,3 @@
    Some one-liner solutions on FCC exercises. Most are my own doing. Some picked from FCC chat.

    ----Arguments optional----

    function add() {
    return (arguments.length===2 && typeof(arguments[0])==='number' && typeof(arguments[1])==='number') ?
    arguments[0] + arguments[1] :
    (arguments.length===1 && typeof(arguments[0])==='number') ? add.bind(null, arguments[0]) : undefined;
    }

    ----Binary Agents----

    function binaryAgent(str) {
    3 changes: 3 additions & 0 deletions Boo who.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    function boo(bool) {
    return !!bool===bool;
    }
  29. Masd925 revised this gist Mar 2, 2016. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    function add() {
    return (arguments.length===2 && typeof(arguments[0])==='number' && typeof(arguments[1])==='number') ?
    arguments[0] + arguments[1] :
    (arguments.length===1 && typeof(arguments[0])==='number') ? add.bind(null, arguments[0]) : undefined;
    }
  30. Masd925 created this gist Mar 2, 2016.
    238 changes: 238 additions & 0 deletions one-liners.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,238 @@
    Some one-liner solutions on FCC exercises. Most are my own doing. Some picked from FCC chat.

    ----Arguments optional----

    function add() {
    return (arguments.length===2 && typeof(arguments[0])==='number' && typeof(arguments[1])==='number') ?
    arguments[0] + arguments[1] :
    (arguments.length===1 && typeof(arguments[0])==='number') ? add.bind(null, arguments[0]) : undefined;
    }

    ----Binary Agents----

    function binaryAgent(str) {
    return str.split(" ").map(function(elem){
    return String.fromCharCode(parseInt(elem,2));
    }).join("");
    }

    ----Boo who----

    function boo(bool) {
    return !!bool===bool;
    }

    ----Caesars Cipher----

    function rot13(str) {
    return str.split("").map(function(char){
    return (char.charCodeAt(0)>64 && char.charCodeAt(0)<91) ? String.fromCharCode(char.charCodeAt(0)%26+65) : char;
    }).join("");
    }

    ----Check for palindromes----

    function palindrome(str) {
    return str.replace(/[\W_]/g,"").toLowerCase().split("").every(function(elem,index,array){
    return elem===array[array.length-1-index];
    });
    }

    ----Chunky monkey----

    function chunk(arr, size) {
    return arr.length ? [arr.splice(0,size)].concat(chunk(arr,size)):[];
    }

    ----Confirm the ending----

    function end(str, target) {
    return str.slice(-target.length)===target;
    }

    ----Counting cards----

    function cc(card) {
    return (count+={2:1,3:1,4:1,5:1,6:1,7:0,8:0,9:0,10:-1,J:-1,Q:-1,K:-1,A:-1}[card]) + " " + (count>0 ? "Bet" : "Hold");
    }

    ----Diff two arrays----

    function diff(arr1, arr2) {
    return arr1.concat(arr2).filter(function(val, index, array){
    return array.indexOf(val)===array.lastIndexOf(val);
    });
    }

    ----DNA pairing----

    function pair(str){
    return Array.prototype.map.call(str, function(val){
    return [val,{A:'T', T: 'A', C: 'G', G: 'C'}[val]];
    });
    }

    ----Drop it----

    function drop(arr, func) {
    return (arr.length && !func(arr[0])) ? drop(arr.slice(1),func) : arr;
    }

    ----Everything be true----

    function every(collection, pre) {
    return collection.every(function(obj){
    return obj[pre];
    });
    }

    ----Falsy bouncer----

    function bouncer(arr) {
    return arr.filter(function(val){return val;});
    }

    ----Finders keepers----

    function find(arr, func) {
    return arr.length ? (func(arr[0]) ? arr[0] : find(arr.slice(1),func)) : undefined;
    }

    ----Find the longest word in a string----

    function findLongestWord(str) {
    return str.split(' ').reduce(function(prev, curr) {
    return Math.max(prev, curr.length);
    }, 0);
    }

    ----Missing letters----

    function fearNotLetter(str) {
    if (str.length>1) return str.charCodeAt(1)===str.charCodeAt(0)+1 ? fearNotLetter(str.slice(1)) : String.fromCharCode(str.charCodeAt(0)+1);
    }

    ----Mutations----

    function mutation(arr) {
    return arr[1].toLowerCase().split("").every(function(val, index, array){
    return arr[0].toLowerCase().indexOf(val)>-1;
    });
    }

    ----Pairwise----

    function pairwise(arr, arg) {
    return arr.reduce(function(prev,curr,index){
    arr.forEach(function(elem,ind){
    if (ind>index && curr+elem===arg && prev.indexOf(index)===-1 && prev.indexOf(ind)===-1) prev.push(index,ind);
    });
    return prev;
    },[]).reduce(function(cur,pre){return cur+pre;},0);
    }

    ----Repeat a string----

    function repeat(str, num) {
    return num>0 ? str+repeat(str,num-1) : "";
    }

    ----Return largest numbers in arrays----

    function largestOfFour(arr) {
    return arr.map(function(innerArray){
    return Math.max.apply(null,innerArray);
    });
    }

    ----Reverse a string----

    function reverseString(str) {
    return str.length ? reverseString(str.substring(1))+str.charAt(0) : "";
    }

    ----Roman numeral converter----

    function convert(num) {
    return Array.prototype.reduce.call(num.toString(),function(prev,curr,index,array){
    return prev.concat([[0],[1],[1,1],[1,1,1],[1,5],[5],[5,1],[5,1,1],[5,1,1,1],[1,10]][curr].map(function(elem){
    return elem*Math.pow(10,array.length-1-index);
    }));
    },[]).map(function(elem){
    return ['M', 'D', 'C', 'L', 'X', 'V', 'I'][[1000,500,100,50,10,5,1].indexOf(elem)];
    }).join("");
    }

    ----Seek and destroy----

    function destroyer(arr) {
    return arr.filter(function(val) {
    return Array.prototype.indexOf.call(this,val,1)===-1;
    },arguments);
    }

    ----Sorted union----

    function unite(arr1, arr2, arr3) {
    return Array.prototype.reduce.call(arguments, function(prev,curr){
    return prev.concat(curr).filter(function(val, index, array){
    return array.indexOf(val)===index;
    });
    });
    }

    ----Steamroller----

    function steamroller(arr) {
    return arr.length ? (Array.isArray(arr[0]) ? steamroller(arr.shift()) : [arr.shift()]).concat(steamroller(arr)) : [];
    }

    ----Sum all primes----

    function sumPrimes(num) {
    return arguments.length!==1 ?
    num>1 ?
    sumPrimes(num-1, arguments[1].filter(function(val){return val%num!==0;}).concat(num))
    :
    arguments[1].reduce(function(a,b){return a+b;})
    :
    num>1 ? sumPrimes(num-1, [num]) : 0;
    }

    ----Symmetric difference----

    function sym(args) {
    return Array.prototype.slice.call(arguments).reduce(function(prev, curr){
    return prev.concat(curr.filter(function(val, index){
    return curr.indexOf(val)===index;
    })).filter(function(val,ind,array){
    return array.indexOf(val)===array.lastIndexOf(val);
    });
    }, []);
    }

    ----Title case a sentence----

    function titleCase(str) {
    return str.split(' ').map(function(val){
    return val.charAt(0).toUpperCase() + val.substr(1).toLowerCase();
    }).join(' ');
    }

    ----Where art thou----

    function where(collection, source) {
    return collection.filter(function(obj){
    return Object.keys(source).every(function(key){
    return obj[key]===source[key];
    });
    });
    }

    ----Where do I belong----

    function where(arr, num) {
    return arr.reduce(function(prev, curr){
    return curr<num ? prev+1 : prev;
    },0);
    }