Skip to content

Commit

Permalink
feat: add half task
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Shmelkov committed Oct 1, 2019
1 parent c5340ea commit 8c1900b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"url": "https://github.com/yankouskia/additional_6/issues"
},
"devDependencies": {
"mocha": "^3.2.0"
"mocha": "^6.2.0"
},
"homepage": "https://github.com/yankouskia/additional_6#readme"
}
48 changes: 47 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
module.exports = function zeros(expression) {
// your solution

partsOfExp = expression.split('*')

singleFactorials = []
doubleFactorials = []
partsOfExp.forEach(parseFactorial)
factorials = []
let result = BigInt(1)

function parseFactorial(item) {
if (item.match(/\d+!!/g)) {
doubleFactorials.push(Number(item.match(/\d+/g)))
} else {
singleFactorials.push(Number(item.match(/\d+/g)))
}
}

for (let index = 0; index < singleFactorials.length; index++) {
factorials.push(BigInt(doSingleFactorial(singleFactorials[index])))
}

for (let index = 0; index < doubleFactorials.length; index++) {
factorials.push(BigInt(doDoubleFactorial(doubleFactorials[index])))
}

function doSingleFactorial(number){
return (number != 1) ? number * doSingleFactorial(number - 1) : 1;
}
function doDoubleFactorial(number){
if (number % 2 === 0) {
return (number != 2) ? number * doDoubleFactorial(number - 2) : doSingleFactorial(2);
} else {
return (number != 1) ? number * doDoubleFactorial(number - 2) : 1;
}
}

console.log(factorials)
//multiply results
for (let index = 0; index < factorials.length; index++) {
result *= BigInt(factorials[index])
}
console.log(result)
if (String(result).match(/[0]+\b/g) === null) {
return 0
} else {
return String(result).match(/[0]+\b/g)[0].length
}
}

0 comments on commit 8c1900b

Please sign in to comment.