finished Tasks

This commit is contained in:
schrom01 2022-10-13 13:49:03 +02:00
parent 5af7a5eec9
commit 7648a937bd
2 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,28 @@
const factorial = function(n){
if(typeof(n) == "bigint") {
if(n == 1n || n == 0n){
return 1n
} else {
result = 1n
for(let i=1n; i<= n; i++){
result = result * i
}
return result
}
}
else {
if(n == 1 || n == 0){
return 1
} else {
result = 1
for(let i=1; i<= n; i++){
result = result * i
}
return result
}
}
}
module.exports = { factorial }

View File

@ -0,0 +1,54 @@
require('./scripts.js')
const oldAndLiving = function(scripts){
return (scripts.filter(script => (script.year < 0 && script.living))).map(script => script.name)
}
const numberOfCodes = function({ranges}) {
return ranges.map(range => range[1] - range[0]).reduce((a, b) => a + b, 0)
}
// const numberOfCodes = ({ranges}) =>
// ranges.reduce((curr, [from, to]) => curr+to-from, 0)
const scriptOfSample = function(letter, scripts) {
code = letter.codePointAt(0)
script = scripts.filter(script => script.ranges.filter(range => code >= range[0] && code < range[1]).length > 0)[0]
if(script){
return script.name
}
else {
return 'unknown'
}
}
const scriptsInString = function(text, scripts) {
console.log(text)
let result = {}
for(letter in text){
script = scriptOfSample(text[letter], scripts)
console.log(text[letter], script)
result[script] = (script in result) ? result[script] + 1 : 1
}
return result
}
//console.log(oldAndLiving(SCRIPTS))
//console.log(numberOfCodes(SCRIPTS[3]))
//console.log(scriptOfSample("A", SCRIPTS))
//console.log( scriptOfSample("英", SCRIPTS))
//console.log( scriptOfSample("я", SCRIPTS))
//console.log(scriptsInString('英国的狗说 "JavaScript", "тяв"', SCRIPTS) )
//console.log(scriptsInString("https://pоstfinance.ch", SCRIPTS))
module.exports = { scriptOfSample }