Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Maths/MobiusFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export const mobiusFunction = (number) => {
return primeFactorsArray.length !== new Set(primeFactorsArray).size
? 0
: primeFactorsArray.length % 2 === 0
? 1
: -1
? 1
: -1
}
2 changes: 1 addition & 1 deletion Maths/RowEchelon.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const rowEchelon = (matrix) => {
let result = matrix

// Iterate through the rows (i) and columns (j) of the matrix.
for (let i = 0, j = 0; i < numRows && j < numCols; ) {
for (let i = 0, j = 0; i < numRows && j < numCols;) {
// If the current column has all zero elements below the current row,
// move to the next column.
if (!checkNonZero(i, j, result)) {
Expand Down
2 changes: 1 addition & 1 deletion Project-Euler/Problem013.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function largeSum(bignum) {
let num = 0

while (pos--) {
for (let i = nums.length; i--; ) {
for (let i = nums.length; i--;) {
num += +nums[i].charAt(pos)
}
ret = (num % 10) + ret
Expand Down
2 changes: 1 addition & 1 deletion String/GenerateGUID.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const Guid = () => {
const pattern = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
let currentDateMilliseconds = new Date().getTime()
return pattern.replace(/[xy]/g, (currentChar) => {
const randomChar = (currentDateMilliseconds + Math.random() * 16) % 16 | 0
const randomChar = ((currentDateMilliseconds + Math.random() * 16) % 16) | 0
currentDateMilliseconds = Math.floor(currentDateMilliseconds / 16)
return (
currentChar === 'x' ? randomChar : (randomChar & 0x7) | 0x8
Expand Down
16 changes: 16 additions & 0 deletions factorial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Function to calculate factorial

function factorial(n) {
if (!Number.isInteger(n) || n < 0) {
throw new Error('Enter a non-negative integer')
}

if (n === 0 || n === 1) {
return 1
}

return n * factorial(n - 1)
}

// Example usage
console.log(factorial(5)) // Output: 120
Loading