const shade = 100;
type Shade = 100;Picking the right architecture = Picking the right battles + Managing trade-offs
- Clarify and agree on the scope of the system
- User cases (description of sequences of events that, taken together, lead to a system doing something useful)
- Who is going to use it?
- How are they going to use it?
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 characters
| function checkCashRegister(price, cash, cid) { | |
| var change = cash - price, // The change due | |
| count = 0, | |
| denomArr = [0.01, 0.05, 0.1, 0.25, 1, 5, 10, 20, 100], | |
| denominations = 9, // Number of denominations is a constant, check denomArr.length below | |
| changeArr = [], | |
| // Cash Drawer variables: | |
| bestFactor = 0, | |
| bestDenom = 0, | |
| indexBestDenom = 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 characters
| //This operation runs for 0.79ms - twice as previous version. PASSES for ALL array inputs. | |
| //input expected is: | |
| /* 3 ≤ sequence.length ≤ 5 · 10^4, | |
| *1 ≤ sequence[i] ≤ 1000 | |
| */ | |
| // NB revision, used Array.prototype.reduce() | |
| function arrayMode(sequence) { | |
| var countArr = [], | |
| mod, count =0, | |
| _seq = sequence.slice(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 characters
| //doesnt work yet | |
| function isMAC48Address(inputString) { | |
| MAC = inputString.split('-'); | |
| var regExChar = new RegExp('^[a-zA-Z]'), | |
| regExNum = new RegExp('^[a-zA-Z]'), | |
| bool = false; | |
| console.log(MAC); | |
| if(MAC.length === 6){ | |
| MAC.forEach(function(elem,idx,array){ | |
| if(elem.length === 2){ |
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 characters
| function sym(args) { | |
| var argsArr = Array.from(arguments), | |
| arrLen = argsArr.length, | |
| x = [], | |
| //function to get symmetric Difference of 2 arrays | |
| symDiffOfTwo = function(arr1, arr2){ | |
| //set default value of arr2 - es5 | |
| arr2 = arr2 || [] ; | |
| arr1 = arr1 || [] ; | |
| var diff = arr2.slice(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 characters
| //works but needs improvements | |
| function telephoneCheck(str) { | |
| var isUSPhoneNum = false, | |
| strArr = str.split(''), | |
| numOfBracs = strArr.join('').split('(').length -1, | |
| numsOnly = str.replace(/-|\s|[{()}]|[^0-9\-]/g,""), | |
| numsLen = numsOnly.length, | |
| firstNum = numsOnly.charAt(0), | |
| firstParenth = str.indexOf('('), | |
| secondParenth = str.indexOf(')'), |
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 characters
| function addTogether() { | |
| var args1 = arguments[0],//1st arg to the function | |
| args2 = arguments[1];//2nd arg to the function | |
| if(typeof args1 === 'number'){ | |
| //both arguments are numbers | |
| if(typeof args2 === 'number'){ | |
| return args1 + args2; | |
| } | |
| //one argument missing | |
| if(args2 === 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 characters
| function truthCheck(collection, pre) { | |
| var x = {}; | |
| var count = 0; | |
| var len = collection.length; | |
| for(var i=0;i<len;i++){ | |
| var prop = collection[i][pre]; | |
| /*a JS val like prop evals to true if its not a null,undefined,NaN,(""),0,false*/ | |
| if(collection[i].hasOwnProperty(pre)&& prop){ | |
| count++; | |
| } |
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 characters
| function binaryAgent(str) { | |
| var arr = []; | |
| //seperate array elems between spaces | |
| str = str.split(' ').map(Number) | |
| //convert elems from binary to decimals | |
| .map( function( num ){ return (parseInt(num, 2));}); | |
| //convert binary string into English! | |
| str.forEach(function(code){ | |
| arr.push(String.fromCharCode(code)); | |
| }); |
NewerOlder