text “(1) - 算法任务”由Szymon Zalarski撰写
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text “(1) - 算法任务”由Szymon Zalarski撰写相关的知识,希望对你有一定的参考价值。
let sequenceA = [2,3,9,2,5,1,3,7,10];
let sequenceB = [2,1,3,4,3,10,6,6,1,7,10,10,10];
let sequenceC = [];
let repetitions = {};
let prohibitedNumbers = [];
const createSequencteC = (sequenceA, prohibitedNumbers) => {
sequenceA.map(item => {
if(prohibitedNumbers.includes(item)) {
return false
}
sequenceC.push(item);
})
console.log(sequenceC);
}
const isPrime = (num) => {
let numberOfDivisions = 0;
for(let i = 0; i <= 10; i++) {
if(num % i === 0 && num > 1) {
numberOfDivisions++
}
}
if(numberOfDivisions === 2) {
return true;
} else {
return false;
}
}
const checkDuplicates = (arr) => {
arr.forEach((i) => repetitions[i] = (repetitions[i]||0) + 1);
checkIsNumerOfRepetitionsIsPrime(repetitions)
}
const checkIsNumerOfRepetitionsIsPrime = (repetitions) => {
for(let k in repetitions) {
if(isPrime(repetitions[k]) && repetitions[k] >1 ) {
prohibitedNumbers.push(parseInt(k))
}
}
}
checkDuplicates(sequenceB);
createSequencteC(sequenceA, prohibitedNumbers);
以上是关于text “(1) - 算法任务”由Szymon Zalarski撰写的主要内容,如果未能解决你的问题,请参考以下文章
text 图像由Node.js任务缩小。
text 由SnippLeaf.com创建
text 由Native JS触发输入
text 很棒的博客由其他人发布
text 由action标签提交的mvc表单
text 由div类选择项目的默认选项