Skip to content

Instantly share code, notes, and snippets.

View arizonatribe's full-sized avatar

David Nunez arizonatribe

  • Colorado
View GitHub Profile
@arizonatribe
arizonatribe / reverse_string.js
Created February 23, 2022 01:25
Simple way to reverse a string of characters in JavaScript
/**
* Reverse a string of characters
*
* @function
* @param {string} str A string of characters to reverse
* @returns {string} The original string, but with the characters reversed
*/
function reverseString(str) {
if (typeof str !== "string") {
return undefined
@arizonatribe
arizonatribe / merge_sorted_arrays.js
Created February 23, 2022 01:15
Given two pre-sorted numeric arrays, how do you merge them together with the fewest loops?
/**
* Manually merge two pre-sorted arrays.
*
* @function
* @name mergeSortedArrays
* @param {Array<*>} arrA The first list of values
* @param {Array<*>} arrB The second list of values
* @returns {Array<*>} The blend of both arrays of values
*/
function mergeSortedArrays(arrA = [], arrB = []) {
@arizonatribe
arizonatribe / variable_swap.js
Created February 23, 2022 00:16
Simple way to swap the values for two variables without creating a third variable
let varA = 42
let varB = 67
([varB, varA] = [varA, varB])
@arizonatribe
arizonatribe / greatest_common_divisor.js
Created February 22, 2022 23:42
Determine the greatest common divisor for two given values
/**
* Checks if a given numeric value is an integer
*
* @function
* @name isInteger
* @param {number} val A value to verify is an integer
* @returns {boolean} Whether or not the given value is an integer
*/
function isInteger(val) {
return typeof val === "number"
@arizonatribe
arizonatribe / uniq.js
Created February 22, 2022 23:39
De-duplicate an array of values (several simple ways to do it)
/**
* There isn't a strong need for de-duplicating an array in JavaScript nowadays with `Set` now native to the language.
* For the sake of computer science exercise, other techniques are expected.
* But pragmatically, just use a `Set` and convert it back to an `Array` afterwards. Easy.
*
* @function
* @name uniq
* @param {Array<*>} arr A list of values (may contain duplicates)
* @returns {Array<*>} The original list of values, but with any duplicates removed.
*/
@arizonatribe
arizonatribe / nth_fibonacci_number.js
Created February 22, 2022 20:08
Retrieve a given index from a Fibonacci series
/**
* Retrieve the "nth" number in a fibonacci series.
*
* @function
* @param {number} nth In an ordered fibonacci series, this represents the index at which to pluck a value out of the series.
* @returns {number|undefined} The value corresponding to the provided (zero based) index
*/
function fibonacciNumber(nth) {
/* Bail out if the index isn't valid */
if (!Number.isInteger(nth) || nth < 0) {
@arizonatribe
arizonatribe / fibonacci.js
Last active February 22, 2022 19:33
Calculating a Fibonacci series for a given threshold number.
/**
* Calculates the sum of all the (positive) numbers between zero and a given number.
*
* @function
* @name fibonacciSeries
* @param {number} ceiling The threshold at which to end the sum
* @returns {Array<number>} The (fibonacci) series of all the positive values between zero and the ceiling.
*/
function fibonacciSeries(ceiling) {
/* Bail out if the ceiling isn't valid */
@arizonatribe
arizonatribe / isPrime.js
Created February 22, 2022 17:43
Exploring JavaScript algorithms: efficient way to check if a value is a prime number.
/**
* Checks if a given numeric value is an integer
*
* @function
* @name isInteger
* @param {number} val A value to verify is an integer
* @returns {boolean} Whether or not the given value is an integer
*/
function isInteger(val) {
return typeof val === "number"
@arizonatribe
arizonatribe / Teach.md
Created February 4, 2022 17:31
You can learn something from anyone and everyone on your team (of any skill-level or specialization) if you seek it out.

Incorporate small learning chunks into Sprint planning, and a 5min recap of it at the end of Sprint.

Goals:

  • Improve the ability to communicate and present occupational ideas in a concise manner
  • Help create a roundtable atmosphere
  • Improve our abilities to listen to and understand each other on complex topics
  • Pick up many tips and tidbits that make us more efficient and knowledgeable at work
  • Develop a clearer picture of how we view each others' areas of specialization and unique talents
@arizonatribe
arizonatribe / Sindre.md
Last active February 1, 2022 18:06
A list of interesting, popular and really useful Sindre Sohrus NPM packages

Testing and Scaffolding

  • ava - One of the better alternatives to Mocha and Jest as a unit test runner.
  • yeoman - This used to be the defacto scaffolding solution in the NodeJs world

Low-Level Utils

  • camelcase - Convert a string to camelcase (70M weekly downloads)
  • p-map - Map over a list of promises (a little less necessary in modern JS, but still averages 35M weekly downloads)
  • clean-stack - Prettify a stacktrace (18M weekly downloads)