Last active
April 6, 2017 10:46
-
-
Save Masd925/8b1a9b1d37c322827dcd to your computer and use it in GitHub Desktop.
Revisions
-
Masd925 revised this gist
Mar 30, 2017 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1 @@ Some FCC one-liner solutions -
Masd925 revised this gist
Mar 30, 2017 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal 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]); } -
Masd925 revised this gist
Mar 30, 2017 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal 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; }); } -
Masd925 revised this gist
Mar 30, 2017 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal 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; } -
Masd925 revised this gist
Sep 16, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal 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"); } -
Masd925 revised this gist
Aug 19, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ function steamrollArray(arr) { // recursive return Array.isArray(arr) ? Array.prototype.concat.apply([],arr.map(steamrollArray)):arr; } function steamrollArray(arr) { // non-recursive while (arr.some(Array.isArray)) { arr = Array.prototype.concat.apply([],arr); } -
Masd925 revised this gist
Aug 19, 2016 . 1 changed file with 9 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,10 @@ 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; } -
Masd925 revised this gist
Apr 21, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal 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, Smallest common multiple, and Sum all fibonacci numbers, are not good enough to be shown here. -
Masd925 revised this gist
Apr 8, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ function mutation(arr) { return arr[1].toLowerCase().split("").every(function(val){ return arr[0].toLowerCase().indexOf(val)>-1; }); } -
Masd925 revised this gist
Mar 31, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal 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. -
Masd925 revised this gist
Mar 8, 2016 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1 +1,3 @@ Some FCC one-liner solutions One-liners on Exact change and Inventory update are not good enough to be shown here. -
Masd925 revised this gist
Mar 8, 2016 . 2 changed files with 0 additions and 30 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +0,0 @@ -
Masd925 revised this gist
Mar 7, 2016 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal 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; } -
Masd925 revised this gist
Mar 7, 2016 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal 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; }); } -
Masd925 revised this gist
Mar 7, 2016 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal 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"); } -
Masd925 revised this gist
Mar 4, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,3 @@ function reverseString(str) { return str.length ? reverseString(str.slice(1))+str.charAt(0) : ""; } -
Masd925 revised this gist
Mar 4, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ function rot13(str) { return str.split("").map(function(char){ return ((cc=char.charCodeAt(0))>64 && cc<91) ? String.fromCharCode(cc%26+65) : char; }).join(""); } -
Masd925 revised this gist
Mar 2, 2016 . 30 changed files with 0 additions and 0 deletions.There are no files selected for viewing
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.File renamed without changes.File renamed without changes. -
Masd925 revised this gist
Mar 2, 2016 . 5 changed files with 26 additions and 38 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,41 +3,3 @@ function binaryAgent(str) { return String.fromCharCode(parseInt(elem,2)); }).join(""); } 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 charactersOriginal 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); }); }, []); } 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 charactersOriginal 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(' '); } 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 charactersOriginal 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]; }); }); } 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 charactersOriginal 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); } -
Masd925 revised this gist
Mar 2, 2016 . 7 changed files with 36 additions and 54 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,60 +4,6 @@ function binaryAgent(str) { }).join(""); } ----Symmetric difference---- function sym(args) { 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 charactersOriginal 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) : ""; } 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 charactersOriginal 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(""); } 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 charactersOriginal 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); } 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 charactersOriginal 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; }); }); } 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 charactersOriginal 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)) : []; } 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 charactersOriginal 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; } -
Masd925 revised this gist
Mar 2, 2016 . 5 changed files with 21 additions and 33 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,39 +4,6 @@ function binaryAgent(str) { }).join(""); } ----Reverse a string---- function reverseString(str) { 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 charactersOriginal 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; }); } 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 charactersOriginal 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); } 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 charactersOriginal 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) : ""; } 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 charactersOriginal 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); }); } -
Masd925 revised this gist
Mar 2, 2016 . 4 changed files with 11 additions and 20 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,26 +4,6 @@ function binaryAgent(str) { }).join(""); } ----Mutations---- function mutation(arr) { 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 charactersOriginal 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); } 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 charactersOriginal 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; } 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 charactersOriginal 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); } -
Masd925 revised this gist
Mar 2, 2016 . 11 changed files with 11 additions and 20 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,26 +4,6 @@ function binaryAgent(str) { }).join(""); } ----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.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 charactersOriginal 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; } 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 charactersOriginal 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]; }); } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ function bouncer(arr) { return arr.filter(function(val){return val;}); } -
Masd925 revised this gist
Mar 2, 2016 . 2 changed files with 6 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1 @@ Some FCC one-liner solutions 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 charactersOriginal 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; } -
Masd925 renamed this gist
Mar 2, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Masd925 renamed this gist
Mar 2, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Masd925 revised this gist
Mar 2, 2016 . 8 changed files with 29 additions and 58 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,67 +1,9 @@ function binaryAgent(str) { return str.split(" ").map(function(elem){ return String.fromCharCode(parseInt(elem,2)); }).join(""); } ----Drop it---- function drop(arr, func) { 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 charactersOriginal 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(""); } 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 charactersOriginal 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]; }); } 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 charactersOriginal 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)):[]; } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ function end(str, target) { return str.slice(-target.length)===target; } 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 charactersOriginal 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"); } 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 charactersOriginal 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]]; }); } 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 charactersOriginal 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); }); } -
Masd925 revised this gist
Mar 2, 2016 . 3 changed files with 3 additions and 10 deletions.There are no files selected for viewing
File renamed without changes.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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,3 @@ ----Binary Agents---- function binaryAgent(str) { 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ function boo(bool) { return !!bool===bool; } -
Masd925 revised this gist
Mar 2, 2016 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal 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; } -
Masd925 created this gist
Mar 2, 2016 .There are no files selected for viewing
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 charactersOriginal 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); }