Nope.
This part of my pseudocode
is complete garbage because of math coincedence.
I did bunch of comparisons:
factorization of factorial
versus
factorization of smalllest multiple(provided by fCC test cases for this challenge and some simplest cases)
there is some pattern going on, but I am not sure:
can it be used or I’ve just coded bunch of useless functions(though factorize() is kinda cool one)
major updateI am so dumb of course it can be used, and it is so simple… to refactoring we go
const factorial = (num) => { //??? maybe there are built-in functions for factorial, more efficient
//base case
if (num === 0 || num === 1) {
return 1;
}
//recursive step
else {
return num * factorial(num - 1);
}
}
const factorize = (num) => {
const allSimpleDividers = {};
while (num !== 1) {
for (let i = 2; i <= num; i++) {
//if we found divider and its first occurance >>>
// >>>need new key with value ===1
//also need to reinitialize num and get rid of inner loop( line ref. as note1)
if (num % i === 0 && !(allSimpleDividers.hasOwnProperty(i))) {
allSimpleDividers[i] = 1;
num = num / i;
break;
}
//if we found divider and its NOT first occurance >>>
//>>> simply increment value of relevant key and do (note1)
else if (num % i === 0 && allSimpleDividers.hasOwnProperty(i)) {
allSimpleDividers[i] += 1;
num = num / i;
break;
}
}
}
return allSimpleDividers;
}
console.log(factorize(factorial(3)));//{ '2': 1, '3': 1 }
console.log(factorize(6)); //{ '2': 1, '3': 1 }
console.log('-----------------')
console.log(factorize(factorial(4)));//{ '2': 3, '3': 1 }
console.log(factorize(12)); //{ '2': 2, '3': 1 }
console.log('-----------------')
console.log(factorize(factorial(5)));//{ '2': 3, '3': 1, '5': 1 }
console.log(factorize(60)); //{ '2': 2, '3': 1, '5': 1 }
console.log('-----------------')
console.log(factorize(factorial(7)));//{ '2': 4, '3': 2, '5': 1, '7': 1 }
console.log(factorize(420)); //{ '2': 2, '3': 1, '5': 1, '7': 1 }
console.log('-----------------')
console.log(factorize(factorial(10)));//{ '2': 8, '3': 4, '5': 2, '7': 1 }
console.log(factorize(2520)); //{ '2': 3, '3': 2, '5': 1, '7': 1 }
console.log('-----------------')
console.log(factorize(factorial(13)));//{ '2': 10, '3': 5, '5': 2, '7': 1, '11': 1, '13': 1 }
console.log(factorize(360360)); //{ '2': 3, '3': 2, '5': 1, '7': 1, '11': 1, '13': 1 }
console.log('-----------------')
console.log(factorize(factorial(20)));//{ '2': 18, '3': 8, '5': 4, '7': 2, '11': 1, '13': 1, '17': 1, '19': 1 }
console.log(factorize(232792560)); //{ '2': 4, '3': 2, '5': 1, '7': 1, '11': 1, '13': 1, '17': 1, '19': 1 }
console.log('-----------------')