From 431bcde0714b07ae38d673db77132b28da042219 Mon Sep 17 00:00:00 2001 From: Brandon Rodriguez <brodriguez8774@gmail.com> Date: Sat, 19 Dec 2020 01:26:18 -0500 Subject: [PATCH] Import updated helper_functions file --- src/helper_functions.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/helper_functions.js b/src/helper_functions.js index d412387..5249d41 100644 --- a/src/helper_functions.js +++ b/src/helper_functions.js @@ -1,18 +1,16 @@ /** - * Contains misc helper functions. + * Various helper functions to make JavaScript development easier. + * + * https://git.brandon-rodriguez.com/javascript/helper_functions + * Version 1.0 */ // System Imports. const chalk = require('chalk'); - const readline = require('readline-sync'); - - // User Imports. /** - * Update strings to have an equivalent the "format()" found in Python strings. - * - * Found from https://stackoverflow.com/a/4974690 + * Update strings to have an equivalent to the "format()" function found in Python strings. */ String.prototype.format = function() { let i = 0, args = arguments; @@ -24,9 +22,6 @@ String.prototype.format = function() { /** * Gets human-readible string of current datetime. - * - * Date parsing logic from https://stackoverflow.com/a/5416970 - * Extra padding logic found at https://stackoverflow.com/a/20460414 */ function getCurrentDate() { let currentDate = new Date; @@ -44,9 +39,7 @@ function getCurrentDate() { /** * Pauses current execution to prompt user for yes/no input. - * Returns True on yes response, and False on all other responses. - * - * "Readline" logic from https://stackoverflow.com/a/50890409 + * :return: True on yes response, and False on all other responses. */ function userConfirmation() { @@ -72,7 +65,8 @@ function userConfirmation() { /** - * Custom equivalent of "sleep" in other languages, as per https://stackoverflow.com/a/39914235. + * Equivalent of "sleep" in other languages, to delay code for x milliseconds. + * :param ms: Value in milliseconds to wait (1000 milliseconds = 1 second). */ function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); @@ -81,15 +75,18 @@ function sleep(ms) { /** * Generates a random number between two values. - * :param min: Inclusive floor for random number. - * :param max: Inclusive ceiling for random number. + * :param min: Inclusive floor for random number. Defaults to 0. + * :param max: Inclusive ceiling for random number. Defaults to 10 or [ min+1 ], whichever is greater. */ function generateRandomNum(min, max) { - // Validate input. + + // Validate min. if (isNaN(parseInt(min))) { // Not a valid number. Default to 0. min = 0; } + + // Validate max. if (isNaN(parseInt(max))) { // Not a valid number. Default to 10, or [ min+1 ], whichever is greater. max = 10; @@ -98,6 +95,7 @@ function generateRandomNum(min, max) { } } + // Get random number between values (inclusive). Math.ceil(min); Math.floor(max) return Math.floor(Math.random() * (max - min + 1) + min); -- GitLab