From 7648a937bd42fcd2129b37ba700e8f72a149690c Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 13 Oct 2022 13:49:03 +0200 Subject: [PATCH] finished Tasks --- factorial.js | 28 +++++++++++++++++++++++ script-of-sample.js | 54 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/factorial.js b/factorial.js index e69de29..4950173 100644 --- a/factorial.js +++ b/factorial.js @@ -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 } \ No newline at end of file diff --git a/script-of-sample.js b/script-of-sample.js index e69de29..b6c9972 100644 --- a/script-of-sample.js +++ b/script-of-sample.js @@ -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 } \ No newline at end of file