Remove live code & console.log, leave examples as comments (Geometry, Graphs, Maths).

This commit is contained in:
Eric Lavault
2021-10-10 17:55:08 +02:00
parent 29d2a84090
commit 9212e6d684
18 changed files with 198 additions and 216 deletions

View File

@@ -10,6 +10,6 @@ export const isDivisible = (num1, num2) => {
return num1 % num2 === 0
}
console.log(isDivisible(10, 5)) // returns true
console.log(isDivisible(123498175, 5)) // returns true
console.log(isDivisible(99, 5)) // returns false
// isDivisible(10, 5) // returns true
// isDivisible(123498175, 5) // returns true
// isDivisible(99, 5) // returns false

View File

@@ -45,7 +45,7 @@ const MatMult = (matA, matB) => {
return matC
}
const MatrixExponentiationRecursive = (mat, m) => {
export const MatrixExponentiationRecursive = (mat, m) => {
// Input: mat: 2D Array of Numbers of size n x n
// Output: mat^n: 2D Array of Numbers of size n x n
// Complexity: O(n^3 log m)
@@ -65,20 +65,16 @@ const MatrixExponentiationRecursive = (mat, m) => {
}
}
const main = () => {
const mat = [[1, 0, 2], [2, 1, 0], [0, 2, 1]]
// const mat = [[1, 0, 2], [2, 1, 0], [0, 2, 1]]
// mat ^ 0 = [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ]
console.log(MatrixExponentiationRecursive(mat, 0))
// // mat ^ 0 = [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ]
// MatrixExponentiationRecursive(mat, 0)
// mat ^ 1 = [ [ 1, 0, 2 ], [ 2, 1, 0 ], [ 0, 2, 1 ] ]
console.log(MatrixExponentiationRecursive(mat, 1))
// // mat ^ 1 = [ [ 1, 0, 2 ], [ 2, 1, 0 ], [ 0, 2, 1 ] ]
// MatrixExponentiationRecursive(mat, 1)
// mat ^ 2 = [ [ 1, 4, 4 ], [ 4, 1, 4 ], [ 4, 4, 1 ] ]
console.log(MatrixExponentiationRecursive(mat, 2))
// // mat ^ 2 = [ [ 1, 4, 4 ], [ 4, 1, 4 ], [ 4, 4, 1 ] ]
// MatrixExponentiationRecursive(mat, 2)
// mat ^ 5 = [ [ 1, 4, 4 ], [ 4, 1, 4 ], [ 4, 4, 1 ] ]
console.log(MatrixExponentiationRecursive(mat, 5))
}
main()
// // mat ^ 5 = [ [ 1, 4, 4 ], [ 4, 1, 4 ], [ 4, 4, 1 ] ]
// MatrixExponentiationRecursive(mat, 5)

View File

@@ -10,7 +10,7 @@ const matrixCheck = (matrix) => {
if (index === 0) {
columnNumb = matrix[index].length
} else if (matrix[index].length !== columnNumb) {
console.log('The columns in this array are not equal')
// The columns in this array are not equal
} else {
return columnNumb
}
@@ -21,7 +21,7 @@ const matrixCheck = (matrix) => {
const twoMatricesCheck = (first, second) => {
const [firstRowLength, secondRowLength, firstColLength, secondColLength] = [first.length, second.length, matrixCheck(first), matrixCheck(second)]
if (firstRowLength !== secondColLength || secondRowLength !== firstColLength) {
console.log('These matrices do not have a common side')
// These matrices do not have a common side
return false
} else {
return true
@@ -44,7 +44,7 @@ const initiateEmptyArray = (first, second) => {
// Finally, `matrixMult` uses `Array.prototype.push()`, multiple layers of nested `for` loops, the addition assignment `+=` operator and multiplication operator `*` to perform the dot product between two matrices of differing sizes.
// Dot product, takes the row of the first matrix and multiplies it by the column of the second matrix, the `twoMatricesCheck` tested to see if they were the same size already.
// The dot product for each iteration is then saved to its respective index into `multMatrix`.
const matrixMult = (firstArray, secondArray) => {
export const matrixMult = (firstArray, secondArray) => {
const multMatrix = initiateEmptyArray(firstArray, secondArray)
for (let rm = 0; rm < firstArray.length; rm++) {
const rowMult = []
@@ -66,26 +66,26 @@ const matrixMult = (firstArray, secondArray) => {
return multMatrix
}
const firstMatrix = [
[1, 2],
[3, 4]
]
// const firstMatrix = [
// [1, 2],
// [3, 4]
// ]
const secondMatrix = [
[5, 6],
[7, 8]
]
// const secondMatrix = [
// [5, 6],
// [7, 8]
// ]
console.log(matrixMult(firstMatrix, secondMatrix)) // [ [ 19, 22 ], [ 43, 50 ] ]
// matrixMult(firstMatrix, secondMatrix) // [ [ 19, 22 ], [ 43, 50 ] ]
const thirdMatrix = [
[-1, 4, 1],
[7, -6, 2]
]
const fourthMatrix = [
[2, -2],
[5, 3],
[3, 2]
]
// const thirdMatrix = [
// [-1, 4, 1],
// [7, -6, 2]
// ]
// const fourthMatrix = [
// [2, -2],
// [5, 3],
// [3, 2]
// ]
console.log(matrixMult(thirdMatrix, fourthMatrix)) // [ [ 21, 16 ], [ -10, -28 ] ]
// matrixMult(thirdMatrix, fourthMatrix) // [ [ 21, 16 ], [ -10, -28 ] ]

View File

@@ -1,7 +1,7 @@
/*
author: Theepag
*/
const factorialize = (num) => {
export const factorialize = (num) => {
// Step 1. variable result to store num
let result = num
// If num = 0 OR 1, the factorial will return 1
@@ -14,6 +14,3 @@ const factorialize = (num) => {
// Step 3. Return the factorial
return result
}
// test
console.log(factorialize(5))
console.log(factorialize(4))

View File

@@ -4,14 +4,7 @@
* Return the result.
*/
const decimalIsolate = (number) => {
export const decimalIsolate = (number) => {
const ans = parseFloat((number + '').replace(/^[-\d]+./, '.'))
return isNaN(ans) === true ? 0 : ans
}
// testing
console.log(decimalIsolate(35.345))
console.log(decimalIsolate(56.879))
console.log(decimalIsolate(89.5643))
console.log(decimalIsolate(38.00))
console.log(decimalIsolate(33))

View File

@@ -4,10 +4,6 @@
* else false
*/
const isOdd = (value) => {
export const isOdd = (value) => {
return !!((value & 1))
}
// testing
console.log(isOdd(2))
console.log(isOdd(3))