Skip to content

Instantly share code, notes, and snippets.

View NikoEscobar's full-sized avatar
🐺
<Lobo /> Game Dev

Níko Escobar NikoEscobar

🐺
<Lobo /> Game Dev
  • @CrystalGameStd;
  • Brazil - SP
View GitHub Profile

How to use async/await without try/catch block

We can use something like this:

async function resolveToNumber () {
  const promise = Promise.resolve(1)
  const [error, result] = await to(promise)
  console.log(error, result) // [null, 1] -> Here we have the result, and error will be null
}
@NikoEscobar
NikoEscobar / Vectors.md
Last active February 7, 2024 11:05
Vector - Linear Algebra Concepts

Game Mathematics

Linear Algebra

  • Vectors

Terminoly

Vector in R²

  • Vector: An ordered list of numbers.
@NikoEscobar
NikoEscobar / EchelonForms.md
Last active January 3, 2024 00:12
Echelon Forms - Row Reduction Algorithms for Solving Systems of Linear Equations

Game Mathematics

Linear Algebra

  • Matrices

Writing Systems

$1x + 1y = 5$

@NikoEscobar
NikoEscobar / rowReductionAlgorithms.js
Created December 31, 2023 18:09
Row Reduction Algorithms for Solving Systems of Linear Equations in JavaScript
/*
This JavaScript code snippet implements row reduction algorithms for solving systems of linear equations.
The rowReductionAlgorithms function provides methods for row replacement, interchange, and scaling operations on matrices.
The example cases demonstrate the application of these algorithms to augmented matrices representing systems of linear equations.
The code supports operations like row replacement, interchange, and scaling, providing a flexible tool for solving systems of linear equations.
Each step is illustrated with examples, showcasing the transformation of augmented matrices to their row-reduced echelon form.
*/
@NikoEscobar
NikoEscobar / distributePercentage.js
Created October 23, 2023 10:55
This function subtracts an amount from the elements in an array until the amount reaches zero. Then, it distributes the original amount value equally among the remaining array elements.
const parseStringPercentToFloat = percentageArray => percentageArray.map(percentage => parseFloat(percentage.slice(0, -1)) / 100);
const parseFloatToStringPercent = percentageArray => percentageArray.map(floatValue => (floatValue * 100).toFixed(2) + "%");
const areArraysEqual = (arr1, arr2) => {
if (arr1.length !== arr2.length) {
return false;
}
return arr1.every((element, index) => element === arr2[index]);
@NikoEscobar
NikoEscobar / BacktrackingAlgorithm.ts
Last active March 26, 2023 00:34
A collection of backtracking algorithms implemented in TypeScript for studying
//=========================- - Backtracking Algorithms - -=========================//
/*
- Backtracking algorithms:
are a type of algorithmic technique that is used to solve problems by trying out different
possible solutions and "backtracking" or undoing a choice when it is found to be incorrect or not feasible.
These algorithms are useful for solving problems where there are many possible solutions,
but only a few of them are actually valid or optimal.
- Sudoku puzzles: Backtracking algorithms are often used to solve Sudoku puzzles, which involve filling a 9x9 grid with
@NikoEscobar
NikoEscobar / DynamicProgrammingAlgorithm.ts
Last active March 18, 2023 01:31
A collection of dynamic programming algorithms implemented in TypeScript for studying
//=========================- - Dynamic Programming Algorithms - -=========================//
/*
- Dynamic Programming:
is a problem-solving technique that involves breaking down a complex problem into smaller, simpler
subproblems and solving each subproblem only once, storing the results to avoid redundant calculations.
The technique is based on the idea of using the solutions of previously solved subproblems to solve the larger problem.
- Optimization problems: Dynamic Programming algorithms can be used to solve optimization problems, such as the Knapsack
problem, where the goal is to maximize the value of objects that can be placed in a knapsack subject to its weight capacity.
@NikoEscobar
NikoEscobar / GraphAlgorithm.ts
Last active March 12, 2023 21:15
A collection of graph search algorithms implemented in TypeScript for studying
//=========================- - Search Algorithms - -=========================//
//- Binary Search
//Binary Search assumes that the input array is already sorted in ascending order.
function binarySearch(arr: number[], target: number, start = 0, end = arr.length - 1) {
if (start > end) return -1
const mid = Math.floor((start + end) / 2)
@NikoEscobar
NikoEscobar / SortingAlgorithm.ts
Last active March 17, 2023 19:04
A collection of sorting algorithms implemented in TypeScript for studying
// - - Sorting Algorithms
// - Bubble Sort - O(n^2) - Quadratic Time
// - Merge Sort - O(n log n) - Quasilinear Time
// - Quick Sort - O(n log n) - Quasilinear Time
// - Heap Sort - O(n log n) - Quasilinear Time
// - Counting Sort - O(n + k) - where k is the range of the input integers
// - Radix Sort - O(d(n+k)) - where d is the number of digits in the input integers and k is the range of the input integers
// - Bucket Sort - O(n + k) - where k is the number of buckets used
// - insertion sort - O(n^2) - Quadratic Time
// - selection sort - O(n^2) - Quadratic Time