我试图摆脱产品数组中没有质数或没有 5 位数字的所有数字。在最后一个 for 循环中拼接它们之后,products 数组仍然有不满足我的 if 条件的数字。
let arr1 = [222, 223, 225 ,227, 232, 233, 235, 237,252, 253, 255, 257, 272, 273, 275, 277, 322, 323, 325, 327, 332, 333, 335, 337, 352, 353, 355, 357, 372, 373, 375, 377, 522, 523, 525, 527, 532, 533, 535, 537, 552,553,555, 557, 572, 573, 575, 577, 722, 723, 725, 727, 732, 733, 735, 737, 752, 753, 755, 757, 772, 773, 775, 777]
let arr2 = [22, 23, 25, 27, 32, 33,35, 37, 52, 53, 55, 57, 72, 73, 75,77]
products = []
for (var i=0; i< arr1.length; i++){
for (var j=0; j< arr2.length; j++){
products.push(arr1[i]*arr2[j])
}
}
// console.log(products.length);
function not_prime(num){
var str1 = num.toString()
if (
str1.indexOf(2) > -1 ||
str1.indexOf(3) > -1 ||
str1.indexOf(5) > -1 ||
str1.indexOf(7) > -1 ||
str1.length != 5) {
return false;
}
return true;
}
for (var i=0; i< products.length; i++){
if (not_prime(products[i])) {
products.splice(i, 1);
}
}
console.log(products)
小唯快跑啊
鸿蒙传说
相关分类