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
| # Write your own unit tests and testing environment | |
| def unit_test(function_to_test, test_input, expected_output): | |
| function_output = function_to_test(test_input) | |
| try: | |
| assert function_output == expected_output | |
| print(unit_test_response(True, test_input, function_output, expected_output)) | |
| except AssertionError: | |
| print(unit_test_response(False, test_input, function_output, expected_output)) | |
| def unit_test_response(correct, test_input, function_output, expected_output): |
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
| """ | |
| The goal here is to gather the user's first and last name using the input() command | |
| and then to print the user's initials | |
| We also want to make sure that those inputs are valid alpha characters because nobody | |
| except for an impostor robot would have a name with numbers in it! INPUT VALIDATION TIME | |
| To accomplish this we need to "sanitize" the input before it is passed along to the rest | |
| of the codebase |
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 works | |
| def printHelloWorld(): | |
| print('hello word') | |
| def returnPrintHelloWorld(): | |
| return print('hello world') # output: syntax error | |
| """ | |
| To answer the original question: Why do you use a return statement on the return 5 |
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 conditionalRecursion(n) { | |
| if (n < 2) return n; | |
| return conditionalRecursion(n - 1) + conditionalRecursion(n - 2); | |
| } | |
| const tests = [ | |
| [1, 3, 5, 7], | |
| [0, 1, 1, 2], | |
| [2, 4, 6, 8], | |
| [0, 1, 2, 3], |
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
| router.post('/update', (req, res) => { | |
| const respond = require('./tools/respond'); | |
| const update = require('./tools/update'); | |
| const body = req.body; | |
| const arguments = body.text; | |
| if(tools.verify.slash(body.token)){ | |
| if(~arguments.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
| argumentParser = arguments => { | |
| const acceptedUpdateItems = ['gitHub', 'blog', 'portfolio', 'story', 'projects', 'certifications']; | |
| let error; | |
| let output = argumentSplitter(arguments); | |
| let item = output.item; | |
| // initial check to ensure the update item is valid | |
| if(!~acceptedUpdateItems.indexOf(item)) return `invalid update item [\`${item}\`]\n Use \`/update help\` for a list of available update items.`; |
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
| errorScanAndModify = (item, flag, data) => { | |
| let expectedFlags; | |
| switch(item){ | |
| case 'projects': | |
| expectedFlags = ['name', 'n', 'url', 'u', 'git', 'g', 'date', 'd']; | |
| break; | |
| case 'gitHub': | |
| case 'blog': | |
| case 'portfolio': |
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
| argumentParser = arguments => { | |
| const output = argumentSplitter(arguments); | |
| const item = output.item; | |
| const pairsArray = output.pairsArray; | |
| let flagDataPairs = {}; | |
| pairsArray.forEach( pairString => { | |
| let flag = pairString.slice(0, pairString.indexOf(' ')); | |
| let data = pairString.slice(pairString.indexOf(' ')+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 characters
| // scans a custom attachment object for errors | |
| errorScan = (type, customAttachment) => { | |
| const expectedKeys = ['text', 'callback_id', 'actions']; | |
| const expectedSubKeys = type === 'menu' ? ['name', 'type', 'data_source'] : ['text', 'name', 'type']; | |
| const keysError = verifyKeys(customAttachment, expectedKeys, 'outer attachment properties'); | |
| if(keysError){ | |
| return keysError; | |
| } |
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
| // Excerpt from controller.js focusing on the /update route that Slack sends all /update requests to | |
| router.post('/update', (req, res) => { | |
| const respond = require('./tools/respond'); | |
| const body = req.body; | |
| const arguments = body.text; | |
| if(tools.verify.slash(body.token)){ | |
| if(~arguments.indexOf(' ')){ |