Skip to content

Latest commit

 

History

History
713 lines (422 loc) · 16.8 KB

README.md

File metadata and controls

713 lines (422 loc) · 16.8 KB

Table of Contents

Numbers

Class for working with numbers and numerical data.

randomInt

Get a random integer between the given range.

Parameters

Returns Number The random integer between the min and max input.

randomFloat

Get a random float between the given range.

Parameters

Returns Number The random float between the min and max input.

normalize

Normalize a number between 0 and 1 based on a known minimum and maximum value.

Parameters

  • val Number The value to normalize.
  • min Number Minimum extent.
  • max Number Maximum extent.

Returns Number The random float between the min and max input.

normalizeToRange

Normalize a number between a custom range (max,min) based on a known minimum and maximum value of the original dataset.

Parameters

  • val Number The value to normalize.
  • minOriginal Number The minimum extent in the original range.
  • maxOriginal Number The maximum extent in the original range.
  • minNew Number The minimum extent in the new, custom range.
  • maxNew Number The maximum extent in the new, custom range.

Returns Number

Arrays

Class for working with arrays of any types

summarize

Find unique items within the array and count frequency of occurrence within the array.

Parameters

  • array Array A an array of values (string, number).

Returns Object Object containing the unique keys of the array, and counts of occurrence in the source array.

chunk

Chunk one flat array into a series of arrays of a certain size.

Parameters

  • array Array A an array of values (string, number, etc.).
  • size Number The size of chunks to split the array into.

Returns Array<Array> An array containing arrays of the specified size, containing the original data from the flat array.

flatten

Flattens n-nested arrays into one array of values.

Parameters

  • array Array A an array containing arrays nested to any amount (n).
  • result (optional, default [])

Returns Array A flat array of values/objects extracted from the nested arrays.

ArraysObjective

Class for working with arrays containing objects with key/value data.

groupBy

Group an array of objects by similar properties.

Parameters

  • array Array<Object> An array of objects with similar properties.
  • key String The unique key to group by.

Returns Object Object containing child objects which contain the individual data points corresponding to the property key used for grouping.

sortBy

Sort an array of objects with similar properties by a shared key's value.

Parameters

  • array Array<Object> An array of objects with similar properties.
  • key String The unique key to merge by.
  • descending Boolean Whether to merge descending (default), or ascending. (optional, default true)

Returns Array<Object> Array of objects sorted by the key's value across occurrences.

min

Get the minimum value of a key in an array containing objects with that key.

Parameters

  • array Array A an array containing objects.
  • key String A key which exists in the objects in the array, with associated numerical values.

Returns Number The minimum value of all the keys in the object array.

max

Get the maximum value of a key in an array containing objects with that key.

Parameters

  • array Array A an array containing objects.
  • key String A key which exists in the objects in the array, with associated numerical values.

Returns Number The maximum value of all the keys in the object array.

normalizeByKey

Normalize the values in an object array associated with a specific key between 0 and 1 or a custom range based on the minimums and maximums contained in the object array by that key.

Parameters

  • array Array A an array containing objects.
  • key String A key which exists in the objects in the array, with associated numerical values.
  • newMin Number (Optional) A custom minimum value to normalize to. (optional, default 0)
  • newMax Number (Optional) A custom maximum value to normalize to. (optional, default 1)

Returns Array The modified object array.

normalizeByKeys

Normalize the values in an object array associated with specific keys between 0 and 1 or a custom range based on the minimums and maximums contained in the object array by those keys.

Parameters

  • array Array A an array containing objects.
  • keys Array<String> An array of keys which exists in the objects in the array, with associated numerical values.
  • newMin Number (Optional) A custom minimum value to normalize to. (optional, default 0)
  • newMax Number (Optional) A custom maximum value to normalize to. (optional, default 1)

Returns Array The modified object array.

normalizeAuto

Normalize all the values in an object array associated with keys which have numerical value pairs between 0 and 1 or a custom range based on the minimums and maximums contained in the object array by those keys.

Parameters

  • array Array A an array containing objects.
  • newMin Number (Optional) A custom minimum value to normalize to. (optional, default 0)
  • newMax Number (Optional) A custom maximum value to normalize to. (optional, default 1)

Returns Array The modified object array.

hierarchyFromFlat

Turn a flat array of objects containing common properties into a nested object hierarchy based on parent/child keys. ex. Folders, File Versions, etc.

Parameters

  • array Array<Object> A an array of objects.
  • parentKey String The common property of the objects to establish primary identity.
  • childKey String The common property of the objects to establish parent -> child relationships.

Returns Array<Object> An array of objects, nested using the .children accessor based on the parent -> child hierarchy established.

ArraysNumerical

Class for working with arrays containing numbers and numerical data.

sum

Sum the values of an array.

Parameters

Returns Number The sum of values in the array.

max

Get the maximum value in the array.

Parameters

Returns Number The maximum of the values in the array.

min

Get the minimum value in the array.

Parameters

Returns Number The minimum of the values in the array.

Strings

Class for working with string data.

checkNull

Check whether a string is null/empty and return a workable string.

Parameters

  • str String The string to check for null/empty.

Returns String A full or empty string.

removeNonPrintable

Remove non-printable (non-ASCII) characters from a string.

Parameters

  • str String The string to clean of non-printable characters.

Returns String String without the non-ASCII characters.

removeNonPathable

Remove non-pathable characters from a string.

Parameters

  • str String The string to clean of non-pathable characters.

Returns String String without the path-breaking characters.

createUniqueID

Create a random, unique identifier string.

Returns String A random string with alpha-numeric characters.

StringsCyrillic

Class for working with Cyrillic string data.

allWords

Get an array of all the Cyrillic words from a monolithic string.

Parameters

  • str The string to break up into individual words.

Returns RegExpMatchArray An array of individual Cyrillic words.

StringsLatin

Class for working with Latin string data.

allWords

Get an array of all the words from a monolithic string.

Parameters

  • str The string to break up into individual words.

Returns RegExpMatchArray An array of individual words.

removeNonAlphaNumeric

Remove non-alpha-numeric characters from a string.

Parameters

  • str String The string to clean of non-alpha-numeric characters.

Returns String String without characters that aren't letters or numbers.

removeNonAlpha

Remove non-alphabetic characters from a string.

Parameters

  • str String The string to clean of non-alphabetic characters.

Returns String String with characters which are only EN letters.

MockData

Class for creating mock data for algorithm/visualization testing.

range

Get a filled array of the corresponding size.

Parameters

  • size Number The amount of numbers in the array.

Returns Array<Number> A filled array the length of the specified size.

packData

Create mock data for a circle-packing algorithm.

Parameters

  • size The amount of data points to create

Returns Array<{r: number, spaceType: (string), id: Number}> An array of objects which can be used as circles in circle-packing algorithm testing.

networkData

Create mock data for a network/graph algorithm.

Parameters

  • size The amount of data points to create

Returns {nodes: Array<{size: Number, x: null, y: null}>, links: Array<{source: number, target: number}>} An array of objects which can be used as nodes and connections in network/graph algorithm testing scenarios.

Sort

Class for sorting arrays containing numerical data.

bubbleSort

Sort an array of numbers using the Bubble Sort algorithm. Iterating through all items in the array, we compare the current item with the next one in the array. If the current one is greater, the positions are swapped. This is repeated until there is no more swapping necessary.

Parameters

Returns Array<Number> An array of sorted numbers.

insertionSort

Sort an array of numbers using the Insertion Sort algorithm. Insertion merge is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. The array elements are compared with each other sequentially and then arranged simultaneously in some particular order. The analogy can be understood from the style we arrange a deck of cards.

Parameters

Returns Array<Number> An array of sorted numbers.

mergeSort

Sort an array of numbers using the Merge Sort algorithm. The MergeSort function repeatedly divides the array into two halves until we reach a stage where we try to perform MergeSort on a subarray of size 1 i.e. p == r. After that, the merge function comes into play and combines the sorted arrays into larger arrays until the whole array is merged.

Parameters

Returns Array<Number> An array of sorted numbers.

quickSort

Sort an array of numbers using the Quick Sort algorithm. QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot. There are many different versions of quickSort that pick pivot in different ways.

Parameters

Returns Array<Number> An array of sorted numbers.

Stack

Stack data structure.

length

Get the count of the number of items in the stack.

Returns number The number of items in the stack.

push

Add an item to the top of the stack.

Parameters

  • item The item to add to the stack.

Returns number The new size of the stack.

pop

Remove the top item from the stack.

Returns any

peek

Get the item at the top of the stack, without removing it.

Returns any The item at the top of the stack.

isEmpty

Whether or not the stack is empty.

Returns boolean Whether or not the stack is empty.

Queue

Queue data structure.