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 getRandomSex() { | |
| return (Math.random() > 0.50) ? 'male' : 'female'; | |
| } | |
| /** | |
| * @private | |
| * @returns {String} | |
| */ | |
| function generateName(gender, parents = []) { | |
| } |
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
| const hasIncomingEdges = node => node.edges.length; | |
| const noIncomingEdges = node => !node.edges.length; | |
| function removeEdge(adjacentVertex, node) { | |
| node.edges = node.edges.filter(vertex => vertex !== adjacentVertex); | |
| return node; | |
| } | |
| function topologicalSort(nodes = []) { | |
| let noEdges = nodes.filter(noIncomingEdges), |
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
| /** | |
| * @desc Find the k most frequently occurring words in a body of text. | |
| * | |
| * @param {String} paragraph | |
| * @param {Integer} k | |
| * @returns {Array} | |
| */ | |
| function getMostFrequentWords(paragraph = '', k = 0) { | |
| if (typeof paragraph !== 'string' || !Number.isInteger(k) || k < 0) { | |
| throw new TypeError('Invalid paragraph text or frequency 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
| => [ 'the', | |
| 'and', | |
| 'a', | |
| 'of', | |
| 'like', | |
| 'with', | |
| 'forests', | |
| 'winds', | |
| 'every', | |
| 'as' ] |
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
| getMostFrequentWords(`THE mountain winds, like the dew and rain, sunshine and snow, are | |
| measured and bestowed with love on the forests to develop their strength and beauty. | |
| However restricted the scope of other forest influences, that of the winds is universal. | |
| The snow bends and trims the upper forests every winter...`, 10); |
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
| // Example of a customer's profile | |
| const profile = { | |
| isLoggedIn: true, | |
| isPremiumMember: true, | |
| firstTimeUser: false | |
| }; | |
| // Examples of evaluating expressions using data from a profile | |
| console.assert( evaluateExpression("isPremiumMember and isLoggedIn", profile) ); | |
| console.assert( evaluateExpression("(isPremiumMember and isLoggedIn) or (firstTimeUser)", profile) ); |
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
| #!/bin/bash | |
| # Exit if any command fails | |
| set -e | |
| echo "Choose a project name. Please use only letters, numbers & underscores:" | |
| read projectName | |
| # Clone Pete Hunt's React Webpack template repository | |
| git clone https://github.com/petehunt/react-webpack-template $projectName |
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(exports) { | |
| 'use strict'; | |
| function getFirstDateInteger(sentence = '') { | |
| const dateMatch = /[0-9]{1,2}/.exec(sentence); | |
| return dateMatch && dateMatch[0] || null; | |
| } | |
| function getFirstYearInteger(sentence = '') { | |
| const yearMatch = /[0-9]{4}/.exec(sentence); |
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
| /** | |
| * @param {Array} population | |
| * @param {Number} sampleSize | |
| */ | |
| function randomSample(population, sampleSize) { | |
| const populationTotal = population.length; | |
| let result = []; | |
| while (sampleSize--) { | |
| const randIndex = Math.floor(Math.random() * populationTotal); |
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
| /** | |
| * @author Cody Romano | |
| * @module VoiceCommand | |
| * @desc Attach JavaScript functions to voice commands | |
| */ | |
| (function(exports) { | |
| 'use strict'; | |
| var proto = VoiceCommand.prototype; |