第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

試圖將數(shù)字保留在只有 5 位數(shù)字和只有數(shù)字 2,3,5,7 的數(shù)組中

試圖將數(shù)字保留在只有 5 位數(shù)字和只有數(shù)字 2,3,5,7 的數(shù)組中

catspeake 2021-12-12 15:27:38
我試圖擺脫產(chǎn)品數(shù)組中沒(méi)有質(zhì)數(shù)或沒(méi)有 5 位數(shù)字的所有數(shù)字。在最后一個(gè) for 循環(huán)中拼接它們之后,products 數(shù)組仍然有不滿足我的 if 條件的數(shù)字。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)
查看完整描述

2 回答

?
小唯快跑啊

TA貢獻(xiàn)1863條經(jīng)驗(yàn) 獲得超2個(gè)贊

問(wèn)題不是很清楚,但是看看這個(gè):


const 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];

const arr2 = [22, 23, 25, 27, 32, 33,35, 37, 52, 53, 55, 57, 72, 73, 75,77];

const products = [];

arr1.forEach(q => {

  arr2.forEach(v => {

    let n = q*v, s = n.toString();

    if(s.length === 5 && s.match(/^[2357]+$/))products.push(n);

  });

});

console.log(products);


查看完整回答
反對(duì) 回復(fù) 2021-12-12
?
鴻蒙傳說(shuō)

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊

使用Array.filter()和Array.some這里。請(qǐng)參閱內(nèi)聯(lián)評(píng)論。


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];


let primes = [2,3,5,7];


products = []  

for (var i=0; i< arr1.length; i++){

  for (var j=0; j< arr2.length; j++){

    products.push(arr1[i]*arr2[j])


  }

}


// Return a filtered array of products that only contains

// items from the original array that pass the provided callback

// function's tests.

let results = products.filter(function(item){


    // Test to see if item contains primes

    let prime = Array.from(item.toString()).some(function(char){

      return primes.indexOf(+char);

    });


    // Return item only if contains a prime and has 5 digits

    return prime && item.toString().length === 5 ? item : null;

});


console.log(results);


查看完整回答
反對(duì) 回復(fù) 2021-12-12
  • 2 回答
  • 0 關(guān)注
  • 227 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)