Best JavaScript code snippet using fast-check-monorepo
main.js
Source:main.js
1// Mustaqil yechish uchun masalalar2//Ex 1 ---------------------------------------3// let n = 5;4// for (let i = 0; i <=n; i++) {5// if (n%i==0) {6// console.log(i);7// }8// }9//Ex 2 ---------------------------------------10// let n = 15;11// let j = 012// for (let i = 0; i <=n; i++) {13// if (n%i==0) {14// j+=i15// }16// }17// console.log(j);18//Ex 3 ---------------------------------------19// let n = 6;20// let j = 021// for (let i = 0; i <n; i++) {22// if (n%i==0) {23// j+=i24// }25// }26// if (j==n) {27// console.log('Mukammal son');28// }else{29// console.log('Mukammal emas');30// }31//Ex 4 ---------------------------------------32// let n = 50;33// for (let i = 1; i <n; i++) {34// let j = 0;35// for (let k = 1; k <i; k++) {36// if (i%k==0) {37// j+=k;38// }39// }40// if(i==j){41// console.log(j);42// }43// }44//Ex 5 ---------------------------------------45// let n = 30;46// for (let i = 0; i <= n; i++) {47// if (i%3==0 && i%5!=0) {48// console.log(i);49// }50// }51//Ex 6 ---------------------------------------52// let n = 6;53// let j = 1;54// for (let i = 2; i < n; i++) {55// if (n % i == 0) {56// j = 0;57// break;58// }59// }60// if (j==1) {61// console.log(`${n} soni toq`);62// } else {63// console.log(`${n} soni toq emas`);64// }65//Ex 7 ---------------------------------------66// let a = 1;67// let b = 10;68// for (let i = a; i <= b; i++) {69// let n = 0;70// for (let j = 2; j < i; j++) {71// if (i % j == 0) {72// n = 1;73// break;74// }75// }76// if (i > 1 && n == 0) {77// console.log(i);78// }79// }80// Boolean 11 ----------------------------------------------------81// let a = 8;82// let b = 4;83// let d = a%2==0 && b%2!=0 || a%2!=0 && b%2==0 || a%2!=0 && b%2!=0 ? "True" : "False"84// console.log(d);85// Boolean 12 ----------------------------------------------------86// let n = 8;87// console.log(n>9);88// Boolean 13 ----------------------------------------------------89// let n = 100;90// console.log(n>99);91// Boolean 15 ----------------------------------------------------92// let n = 82;93// let a = n/10%10;94// let b = n%10;95// console.log(Math.floor(a)==b);96// Boolean 16 ----------------------------------------------------97// let n = 72;98// let a = n/10%10;99// let b = n%10;100// let d = Math.floor(a)+b101// console.log(d%2==0);102// Boolean 17 ----------------------------------------------------103// let n = 72;104// let a = n/10%10;105// let b = n%10;106// let d = Math.floor(a)+b107// console.log(d%2!=0);108// Boolean 18 ----------------------------------------------------109// let n = 101;110// let c = n/100%10111// let a = n/10%10;112// let b = n%10;113// let d = Math.floor(c)+Math.floor(a)+b114// console.log(d%2!=0);115// Boolean 18 ----------------------------------------------------116// let n = 200;117// console.log(n>9999);118// Boolean 19 ----------------------------------------------------119// let n = 57851;120// let a = n/10000%10;121// let b = n/1000%10;122// let c = n/100%10;123// let d = n/10%10;124// let f = n%10;125// let g = Math.floor(a)>Math.floor(b)&&Math.floor(b)>Math.floor(c)&&Math.floor(c)>Math.floor(d)&& Math.floor(d)>f126// console.log(g);127// Boolean 20 ----------------------------------------------------128// let n = 54321;129// let a = n/10000%10;130// let b = n/1000%10;131// let c = n/100%10;132// let d = n/10%10;133// let f = n%10;134// let g = Math.floor(a)<Math.floor(b)&&Math.floor(b)<Math.floor(c)&&Math.floor(c)<Math.floor(d)&& Math.floor(d)<f135// console.log(g);136// Boolean 21 ----------------------------------------------------137// let n = -5;138// if (n<0) {139// console.log(n);140// }else{141// console.log(n+1);142// }143// Boolean 22 ----------------------------------------------------144// let n = 5;145// if (n<0) {146// console.log(n-2);147// }else{148// console.log(n+1);149// }150// Boolean 23 ----------------------------------------------------151// let n = 0;152// if (n<0) {153// console.log(n-2);154// }else if(n>0) {155// console.log(n+1);156// }else{157// console.log(10);158// }159// Boolean 24 ----------------------------------------------------160// let a = 2;161// let b = -2;162// let c = -3;163// let d = 0;164// if(a>0){165// d++166// }167// if(b>0){168// d++169// }170// if (c>0) {171// d++172// }173// console.log(d);174// Boolean 25 ----------------------------------------------------175// let a = 2;176// let b = 2;177// let c = 3;178// let d = 0;179// let e = 0;180// if(a>0){181// d++182// }else{183// e++184// }185// if(b>0){186// d++187// }else{188// e++189// }190// if (c>0) {191// d++192// }else{193// e++194// }195// console.log(d,e);196// Boolean 26 ----------------------------------------------------197// let a = -1;198// let b = 10;199// if(a>b){200// console.log(a,b);201// }else{202// console.log(b,a);203// }204// Funksiya 1 --------------------------------205// let x ;206// let y ;207// function minMax(a,b,c,d) {208// x = a>b && a>c &&a>d ? a : b>a && b>c && b>d ? b : c>a && c>b && c>d ? c : d>a && d>b && d>c ? d : "Hammasi teng"209// y = a<b && a<c &&a<d ? a : b<a && b<c && b<d ? b : c<a && c<b && c<d ? c : d<a && d<b && d<c ? d : "Hammasi teng"210// console.log(x,y);211// }212// minMax(100,100,100,100)213// arrow funksiaya214// let person = 'roboto'215// let welcome = 216// person == 'man'?217// () => console.log('Siz odamsiz'):218// () => console.log('Siz odam emasiz');219// welcome()220// Funksiya 2 --------------------------------221// let newArray = [15,20,17,20,19,20,21,20,23,20]222// for (let i = 0; i < newArray.length; i++) {223// let count = 0;224// for (let j = 2; j < newArray[i]; j++) {225// if (newArray[i]%j==0) {226// count++;227// }228// }229// if(count == 0){230// console.log(newArray[i]);231// }232// }233// Funksiya 3 --------------------------------234// let newArray = [12,13,1,5,1,6,1,4,5];235// let juftArray = [];236// for (let i = 0; i < newArray.length; i++) {237// if (newArray[i]%2==0) {238// juftArray[juftArray.length]=newArray[i]239// }240// }241// console.log(juftArray);242// Array 1 ------------------------------------243// let n = 42;244// let toqSon = []245// for (let i = 0; i <= n*2; i++) {246// if (i%2!=0) {247// toqSon.push(i)248// }249// }250// console.log(toqSon);251// Array2252/*253let n = 5;254let newArray = [];255for(let i = 0; i <= n; i++){256 newArray[newArray.length] = 2**i;257}258console.log(newArray);259*/260// Array3261/*262let n = 5;263let a = 3;264let d = 10;265let newArray = [];266for(let i = 1; i <= n; i++){267 newArray[newArray.length] = a;268 a += d;269}270console.log(newArray);271*/272// Array4273/*274let n = 5;275let a = 3;276let d = 3;277let newArray = [];278for(let i = 1; i <= 5; i++){279 newArray[newArray.length] = a;280 a *= d;281}282console.log(newArray);283*/284// Array5285// let n = 3;286// let a = 0;287// let b = 1;288// let c = 0;289// let newArray = [];290// for(let i = 1; i <= n; i++){291// c = a + b;292// a = b;293// b = c;294// newArray[newArray.length] = c;295// }296// console.log(newArray);297// Array7298/*299let newArray = [2, 3, 4, 5, 6, 7, 8, 10];300let reverseArray = [];301let j = 0;302for(let i = newArray.length - 1, j = 0; i >= 0; i--, j ++){303 reverseArray[j] = newArray[i];304}305console.log(reverseArray);306*/307// Array8308/*309let newArray = [4, 5, 7, 8, 6, 9];310let oddRiseArray = [];311let count = 0;312for(let i = 0; i < newArray.length; i++){313 if(newArray[i] % 2 != 0){314 oddRiseArray[oddRiseArray.length] = newArray[i];315 count++;316 }317}318console.log(oddRiseArray, count);319*/320// Array9321/*322let newArray = [4, 5, 7, 8, 6, 9];323let evenDecreaseArray = [];324let count = 0;325for(let i = newArray.length - 1; i >= 0; i--){326 if(newArray[i] % 2 == 0){327 evenDecreaseArray[evenDecreaseArray.length] = newArray[i];328 count++;329 }330}331console.log(evenDecreaseArray, count);332*/333// Array10334/*335let newArray = [4, 5, 7, 8, 6, 9];336let evenRiseArray = [];337let oddDecreaseArray = [];338let j = 0;339for(let i = 0, j = newArray.length - 1; i < newArray.length; i++, j--){340 if(newArray[i] % 2 == 0){341 evenRiseArray[evenRiseArray.length] = newArray[i];342 } 343 if(newArray[j] % 2 != 0){344 oddDecreaseArray[oddDecreaseArray.length] = newArray[j];345 }346}347console.log(evenRiseArray, oddDecreaseArray);348*/349// Array18350/*351let newArray = [18, 2, 11, 14, 10];352for(let i = 0; i < newArray.length; i++){353 if(newArray[i] < newArray[newArray.length - 1]){354 console.log(newArray[i]);355 break;356 }357 if(i == newArray.length -1){358 console.log(0);359 }360}361*/362// Array19363/*364let newArray = [2, 4, 3, 6, 8, 9, 7];365for(let i = newArray.length - 1; i >= 0; i--){366 if(newArray[i] < newArray[newArray.length - 1] && newArray[i] > newArray[0]){367 console.log(i);368 break;369 } 370 if(i == newArray[0]){371 console.log(0);372 }373}374*/375// Array20376/*377let newArray = [2, 3, 4, 7, 4, 2, 9, 12];378let k = 2;379let l = 6;380let count = 0;381for(let i = k; i < l; i++){382 count += newArray[i];383}384console.log(count);385*/386// Array21387/*388let newArray = [1, 2, 10, 4, 5, 6];389let k = 2;390let l = 5;391let count = 0;392let check = 0;393for(let i = k; i < l; i++){394 count += newArray[i]; 395 check++;396}397console.log(count / check);398*/399// Array22400/*401let newArray = [1, 2, 3, 4, 5, 1, 2];402let k = 2;403let l = 4;404let count = 0;405for(let i = 0; i < newArray.length; i++){406 if(i < k || i > l){407 count += newArray[i];408 }409}410console.log(count);411*/412// Array23413/*414let newArray = [1, 2, 10, 4, 5, 6, 2];415let k = 2;416let l = 3;417let count = 0;418let check = 0;419for(let i = 0; i < newArray.length; i++){420 if(i < k || i > l){421 count += newArray[i];422 check++;423 }424}425console.log(count / check);426*/427// Array24428/*429let newArray = [3, 6, 9, 12, 13];430let a = newArray[1] - newArray[0];431let count = 0;432for(let i = 1; i < newArray.length; i++){433 if(newArray[i] == newArray[i - 1] + a){434 count += 0;435 } else{436 count++;437 break;438 }439}440if(count == 0){441 console.log(a);442} else{443 console.log(0);444}445*/446// Array25447/*448let newArray = [3, 9, 27, 81, 243];449let a = Math.floor(newArray[1] / newArray[0]);450let count = 0;451for(let i = 1; i < newArray.length; i++){452 if(newArray[i] == newArray[i - 1] * a){453 count += 0;454 } else{455 count++;456 break;457 }458}459if(count == 0){460 console.log(a);461} else{462 console.log(0);463}464*/465// Array26466/*467let newArray = [2, 1, 2, 1, 2, 1];468let count = 0;469let i = 0;470if(newArray[0] % 2 == 0){471 for(let j = 0, i = 1; j < newArray.length; j += 2, i += 2){472 if(newArray[j] % 2 == 0){473 count += 0;474 } else{475 count = j;476 break;477 }478 if(newArray[i] % 2 != 0){479 count += 0;480 } else{481 count = i;482 break;483 }484 }485} else{486 for(let j = 0, i = 1; j < newArray.length; j += 2, i += 2){487 if(newArray[j] % 2 != 0){488 count += 0;489 } else{490 count = j;491 break;492 }493 if(newArray[i] % 2 == 0){494 count += 0;495 } else{496 count = i;497 break;498 }499 }500}501if(count == 0){502 console.log(0);503} else{504 console.log(count);505}506*/507// Array27508/*509let newArray = [-1, 2, -2, 3, -3, 4];510let count = 0;511let j = 0;512if(newArray[0] < 0){513 for(let i = 0, j = 1; i < newArray.length; i += 2, j += 2){514 if(newArray[i] < 0){515 count += 0;516 } else{517 count = i;518 break;519 }520 if(newArray[j] > 0){521 count += 0;522 } else{523 count = j;524 break;525 }526 }527} else{528 for(let i = 0, j = 1; i < newArray.length; i += 2, j += 2){529 if(newArray[i] > 0){530 count += 0;531 } else{532 count = i;533 break;534 }535 if(newArray[j] < 0){536 count += 0;537 } else{538 count = j;539 break;540 }541 }542}543if(count == 0){544 console.log(0);545} else{546 console.log(count);547}548*/549// Array28550/*551let newArray = [22, 4, 11, 5, 6, 7, 11, 3, 12];552let smallArray = [];553 554for(let i = 0; i < newArray.length; i++){555 if(i % 2 == 0){556 smallArray[smallArray.length] = newArray[i];557 }558}559console.log(Math.min(...smallArray));560*/561// Array29562/*563let newArray = [22, 43, 11, 5, 6, 7, 11, 31, 12];564let smallArray = [];565 566for(let i = 0; i < newArray.length; i++){567 if(i % 2 != 0){568 smallArray[smallArray.length] = newArray[i];569 }570}571console.log(Math.max(...smallArray));572*/573// let newArray = [10,2,3,1,-100,78];574// for (let i = 0; i < newArray.length; i++) {575// if (newArray[i]<newArray[0]) {576// newArray[0]=newArray[i]577// } 578// }579// console.log(newArray[0]);580// let newArray = [10,2,3,1,-100,8];581// for (let i = 0; i < newArray.length; i++) {582// for (let j = 0; j < newArray.length; j++) {583// if (newArray[j]<newArray[j+1]) {584// let a = newArray[j+1]585// newArray[j+1]=newArray[j]586// newArray[j]=a587// }588// }589// }590// console.log(newArray);591let arr = [10,15,14,17,56,83,100]592let juftArr = []593let toqArr = []594let allArr = []595for (let i = 0; i < arr.length; i++) {596 if (arr[i]%2==0) {597 juftArr[juftArr.length]=arr[i]598 }else{599 toqArr[toqArr.length]=arr[i]600}601}602for (let i = 0; i < juftArr.length; i++) {603 for (let j = 0; j < juftArr.length; j++) {604 if (juftArr[j]<juftArr[j+1]) {605 let a = juftArr[j+1]606 juftArr[j+1]=juftArr[j]607 juftArr[j]=a608 609 }610 }611}612for (let i = 0; i < toqArr.length; i++) {613 for (let j = 0; j < toqArr.length; j++) {614 if (toqArr[j]<toqArr[j+1]) {615 let a = toqArr[j+1]616 toqArr[j+1]=toqArr[j]617 toqArr[j]=a618 619 }620 }621}622let a = 0;623let b = 0;624for (let k = 0; k < arr.length; k++) {625 if(k%2==0){626 arr[k]=juftArr[a]627 a++;628 }else{629 arr[k]=toqArr[b]630 b++;631 }632}...
ahui_qn-lodash_20210717204726.js
Source:ahui_qn-lodash_20210717204726.js
1var ahui_qn = function () {2 // 深度对æ¯å½æ°3 function isEqual(a, b) {4 if (a === b) {5 return true6 }7 var typea = typeof a // è·åæ°æ®ç±»å8 var typeb = typeof b // è·åæ°æ®ç±»å9 if (typea !== typeb) { // ç±»åä¸åè¿åfalse10 return false11 } else { // ç±»åç¸åå¾ä¸èµ°12 if (typea == 'object') { // å°è¿ä¸æ¥ä¸¤ä¸ªæ°æ®ç±»ååªè½æ¯è¦ä¹ä¸¤ä¸ªç¸åç对象æè
æ°ç»è¦ä¹ ä¸ä¸ªå¯¹è±¡ä¸ä¸ªæ°ç»13 if ((Array.isArray(a) && !Array.isArray(b)) || (Array.isArray(b) && !Array.isArray(a))) { // å¤æa , b æ¯å¦ ä¸ä¸ªæ¯æ°ç»ä¸ä¸ªæ¯å¯¹è±¡14 return false15 }16 // å¾åå³å为æ°ç»æå为对象17 if (Array.isArray(a)) { // å¦ææ¯æ°ç»çè¯å
å¤æé¿åº¦æ¯å¦ç¸ç ï¼å¦ææ¯å¯¹è±¡çè¯é£ä¹å¾åèµ°ã18 if (a.length !== b.length) {19 return false20 }21 } else { // å为æ°ç»æè
对象ï¼å¤æå±æ§çæ°éåå
容22 var keysa = Object.keys(a) // å¦ææ¯å¯¹è±¡çè¯å°± å°å¯¹è±¡çå±æ§å转为æ°ç»23 var keysb = Object.keys(b) // å¦ææ¯å¯¹è±¡çè¯å°± å°å¯¹è±¡çå±æ§å转为æ°ç»24 if (keysa.length !== keysb.length) { // 转为æ°ç»åçæ¯å¦é¿åº¦ç¸çï¼å³æ¯ä¸æ¯æ¥æç¸åé¿åº¦çå±æ§å25 return false26 }27 }28 // ä¸é¢æ¯å¯¹æ¯å¯¹è±¡çå±æ§å¼åå±æ§åæ¯å¦ç¸ç29 for (var key in a) { // è·å对象 a çå±æ§å30 if (!(key in b)) { // ç b è¿ä¸ªå¯¹è±¡éé¢æ没ækey(a çå±æ§å)è¿ä¸ªå¼31 return false32 }33 if (!isEqual(a[key], b[key])) { // è¿ä¸ªéå½æ¯å¯¹æ¯ a , b两个对象çå±æ§åçå¼æ¯å¦ç¸çï¼å°±æ¯æ¤å½æ°ç第ä¸ä¸ªifå¤æ为æ¤éå½çç»æ¢æ¡ä»¶34 return false35 }36 }37 return true38 } else {39 return a === b40 }41 }42 }43 function chunk (array, size = 1){ // å°æ°ç»æåæäºç»´æ°ç»ï¼ï¼size为æ¯ä¸ªäºç»´æ°ç»çé¿åº¦44 var newArray = []45 var sum = size46 while (sum) {47 newArray.push(array.splice(0,size))48 sum--49 if (array.length == 0) {50 break51 }52 }53 return newArray54 }55 function compact (array) { // å»é¤æ°ç»åå¼56 var newArray = []57 for (var i = 0; i < array.length; i++) {58 if (array[i]){59 newArray.push(array[i])60 }61 }62 return newArray63 }64 function unique (array) { // æ°ç»å»é65 var newArray = []66 var map = {}67 for (var i = 0; i < array.length; i++) {68 if (array[i] in map) {69 continue70 }else {71 newArray.push(array[i]) 72 map[array[i]] = 073 }74 }75 return newArray76 }77 function flatten (array) {78 return array.reduce((newArray, it) => {79 if (Array.isArray(it)) {80 it.forEach(x => {81 newArray.push(x)82 })83 }else{84 newArray.push(it)85 }86 return newArray87 }, [])88 }89 function flattenDeep (array){ // éä½å¤ç»´æ°ç»ä¸ºä¸ç»´æ°ç»90 return array.reduce((newArray, item) => { // å建ä¸ä¸ªæ°æ°ç»ï¼åæ°ç»ä¼ å
¥çæ¯ä¸ªå
ç´ 91 return newArray.concat(Array.isArray(item) ? flattenDeep(item) : item) 92 },[])93 }94 function flattenDepth (array, depth = 1) { // æå®éç»´æ°é95 if (depth == 0) {96 return array.slice()97 }98 var newArray = []99 for (var i = 0; i < array.length; i++) {100 var item = array[i] 101 if (Array.isArray(item)) {102 item = flattenDepth(item, depth - 1)103 for (var j = 0; j < item.length; j++) {104 newArray.push(item[j])105 }106 }else {107 newArray.push(item)108 }109 }110 return newArray111 }112 113 function fromPairs (array) {114 var map = {}115 for (let i = 0; i < array[0].length; i++) {116 map[array[i][0]] = array[i][1]117 }118 return map119 }120 function forEach (collection , f) {121 for (var i = 0; i < collection.length; i++) {122 f(collection[i], i, collection)123 }124 return collection125 }126 function map(array, f) {127 var newArray = []128 for (var i = 0; i < array.length; i++) {129 newArray.push(f(array[i], i)) // pushè¿ä¸ä¸ªæ°çæ°ç»130 }131 return newArray132 }133 function filter (array, f) {134 var newArray = []135 for (var i = 0; i < array.length; i++) {136 if (f(array[i])) {137 newArray.push(array[i])138 }139 }140 return newArray141 }142 function reduce (array, f, initial) {143 for (var i = 0; i < array.length; i++) {144 initial = f(initial, array[i])145 }146 return initial147 }148 function zip (...array) {149 var newArray = []150 var count = array[0].length151 var sum = 0 // æ§å¶éååæ°ç»ç第å 项152 while(count){153 var temporary = []154 for (var i = 0; i < array.length; i++) {155 temporary.push(array[i][sum])156 }157 count--158 sum++159 newArray.push(temporary)160 }161 return newArray162 }163 164 function unzip(array) {165 var newArray = []166 var count = array[0].length167 var sum = 0 // æ§å¶éååæ°ç»ç第å 项168 while(count){169 var temporary = []170 for (var i = 0; i < array.length; i++) {171 temporary.push(array[i][sum])172 }173 count--174 sum++175 newArray.push(temporary)176 }177 return newArray178 }179 function keys (object) { // è¿åkey180 var newArray = []181 if (typeof object == 'object') {182 for (var k in object) {183 newArray.push(k)184 }185 }else {186 var obj = {}187 for (var i = 0; i < object.length; i++) {188 obj[i] = object[i]189 }190 for (var j in obj) {191 newArray.push(j)192 }193 }194 return newArray195 }196 function values(object) { // è¿åå¼197 var newArray = []198 if (typeof(object) == 'object') {199 for (var k of object) {200 newArray.push(k)201 }202 }else{203 for (var i = 0; i < object.length; i++) {204 newArray.push(object[i])205 }206 }207 return newArray208 }209 function difference (array, ...values) {210 var newArray = array.slice()211 values = values.flat()212 values.forEach((x) => {213 newArray.forEach((j,i) => {214 if (x == j) {215 newArray.splice(i,1)216 }217 })218 })219 return newArray220 }221 function differenceBy (array, values = [], f) {222 var newArray = array.slice()223 values = values.flat()224 if (typeof f == 'function') {225 for (let i = 0; i < values.length; i++) {226 values[i] = f(values[i])227 }228 for (let i = 0; i < newArray.length; i++) {229 newArray[i] = f(newArray[i])230 }231 values.forEach((x) => {232 newArray.forEach((j,i) => {233 if (isEqual(x,j)) {234 array.splice(i,1)235 }236 })237 })238 return array239 }240 241 values.forEach((x) => {242 newArray.forEach((j,i) => {243 if (isEqual(x,j)) {244 newArray.splice(i,1)245 }246 })247 })248 return newArray249 }250 function differenceWith (array, values,f) {251 var newArray = array.slice()252 if (typeof f == 'function') {253 for (let i = 0; i < values.length; i++) {254 values[i] = f(values[i])255 }256 for (let i = 0; i < newArray.length; i++) {257 newArray[i] = f(newArray[i])258 }259 values.forEach((x) => {260 newArray.forEach((j,i) => {261 if (isEqual(x,j)) {262 array.splice(i,1)263 }264 })265 })266 return array267 }268 }269 function drop(array, n = 1) {270 var newArray = array.slice()271 for (let i = 0; i < n; i++) {272 newArray.shift()273 }274 return newArray275 }276 function dropRight(array, n = 1) {277 var newArray = array.slice()278 for (let i = 0; i < n; i++) {279 newArray.pop()280 }281 return newArray282 }283 function concat(array,...values) {284 for (let i = 0; i < values.length; i++) {285 if (Array.isArray(values[i])) {286 values[i].forEach(a => array.push(a))287 }else {288 array.push(values[i])289 }290 }291 return array292 } 293 function fill (array, filler, idx = 0, toIdx = array.length) {294 for (let i = idx; i < toIdx; i++) {295 array[i] = filler296 }297 return array298 }299 function head (array) {300 var newArray = array301 return newArray.shift()302 }303 function indexOf (array, value, fromIndex = 0) {304 for (let i = fromIndex; i < array.length; i++) {305 if (value == array[i]) return i306 }307 return -1308 }309 310 function initial (array) {311 var newArray = []312 for (let i = 0; i < array.length - 1; i++) {313 newArray.push(array[i])314 }315 return newArray316 }317 function intersection (...array) {318 var newArray = []319 for (var i = 0; i < array[0].length; i++) {320 for (var j = 1; j < array.length; j++) {321 if (!(array[j].includes(array[0][i]))) {322 break // 没æç´æ¥break323 } 324 }325 if (j == array.length) { // å½åé¢ä¸¤ä¸ªæ°ç»é½éåå®æå326 newArray.push(array[0][i])327 }328 return newArray329 }330 } 331 332 return {333 chunk : chunk,334 compact : compact,335 unique : unique,336 flatten : flatten,337 flattenDeep : flattenDeep,338 flattenDepth : flattenDepth,339 fromPairs : fromPairs,340 forEach : forEach,341 map : map,342 filter : filter,343 reduce : reduce,344 zip : zip,345 unzip : unzip,346 keys : keys,347 values : values,348 difference : difference,349 differenceBy : differenceBy,350 differenceWith : differenceWith,351 drop : drop,352 dropRight : dropRight,353 concat : concat,354 fill : fill,355 head : head,356 indexOf : indexOf,357 intersection : intersection,358 }...
ahui_qn-lodash_20210717203420.js
Source:ahui_qn-lodash_20210717203420.js
1var ahui_qn = function () {2 // 深度对æ¯å½æ°3 function isEqual(a, b) {4 if (a === b) {5 return true6 }7 var typea = typeof a // è·åæ°æ®ç±»å8 var typeb = typeof b // è·åæ°æ®ç±»å9 if (typea !== typeb) { // ç±»åä¸åè¿åfalse10 return false11 } else { // ç±»åç¸åå¾ä¸èµ°12 if (typea == 'object') { // å°è¿ä¸æ¥ä¸¤ä¸ªæ°æ®ç±»ååªè½æ¯è¦ä¹ä¸¤ä¸ªç¸åç对象æè
æ°ç»è¦ä¹ ä¸ä¸ªå¯¹è±¡ä¸ä¸ªæ°ç»13 if ((Array.isArray(a) && !Array.isArray(b)) || (Array.isArray(b) && !Array.isArray(a))) { // å¤æa , b æ¯å¦ ä¸ä¸ªæ¯æ°ç»ä¸ä¸ªæ¯å¯¹è±¡14 return false15 }16 // å¾åå³å为æ°ç»æå为对象17 if (Array.isArray(a)) { // å¦ææ¯æ°ç»çè¯å
å¤æé¿åº¦æ¯å¦ç¸ç ï¼å¦ææ¯å¯¹è±¡çè¯é£ä¹å¾åèµ°ã18 if (a.length !== b.length) {19 return false20 }21 } else { // å为æ°ç»æè
对象ï¼å¤æå±æ§çæ°éåå
容22 var keysa = Object.keys(a) // å¦ææ¯å¯¹è±¡çè¯å°± å°å¯¹è±¡çå±æ§å转为æ°ç»23 var keysb = Object.keys(b) // å¦ææ¯å¯¹è±¡çè¯å°± å°å¯¹è±¡çå±æ§å转为æ°ç»24 if (keysa.length !== keysb.length) { // 转为æ°ç»åçæ¯å¦é¿åº¦ç¸çï¼å³æ¯ä¸æ¯æ¥æç¸åé¿åº¦çå±æ§å25 return false26 }27 }28 // ä¸é¢æ¯å¯¹æ¯å¯¹è±¡çå±æ§å¼åå±æ§åæ¯å¦ç¸ç29 for (var key in a) { // è·å对象 a çå±æ§å30 if (!(key in b)) { // ç b è¿ä¸ªå¯¹è±¡éé¢æ没ækey(a çå±æ§å)è¿ä¸ªå¼31 return false32 }33 if (!isEqual(a[key], b[key])) { // è¿ä¸ªéå½æ¯å¯¹æ¯ a , b两个对象çå±æ§åçå¼æ¯å¦ç¸çï¼å°±æ¯æ¤å½æ°ç第ä¸ä¸ªifå¤æ为æ¤éå½çç»æ¢æ¡ä»¶34 return false35 }36 }37 return true38 } else {39 return a === b40 }41 }42 }43 function chunk (array, size = 1){ // å°æ°ç»æåæäºç»´æ°ç»ï¼ï¼size为æ¯ä¸ªäºç»´æ°ç»çé¿åº¦44 var newArray = []45 var sum = size46 while (sum) {47 newArray.push(array.splice(0,size))48 sum--49 if (array.length == 0) {50 break51 }52 }53 return newArray54 }55 function compact (array) { // å»é¤æ°ç»åå¼56 var newArray = []57 for (var i = 0; i < array.length; i++) {58 if (array[i]){59 newArray.push(array[i])60 }61 }62 return newArray63 }64 function unique (array) { // æ°ç»å»é65 var newArray = []66 var map = {}67 for (var i = 0; i < array.length; i++) {68 if (array[i] in map) {69 continue70 }else {71 newArray.push(array[i]) 72 map[array[i]] = 073 }74 }75 return newArray76 }77 function flatten (array) {78 return array.reduce((newArray, it) => {79 if (Array.isArray(it)) {80 for (let x of it) {81 newArray.push(x)82 }83 }else{84 newArray.push(it)85 }86 return newArray87 }, [])88 89 }90 function flattenDeep (array){ // éä½å¤ç»´æ°ç»ä¸ºä¸ç»´æ°ç»91 return array.reduce((newArray, item) => { // å建ä¸ä¸ªæ°æ°ç»ï¼åæ°ç»ä¼ å
¥çæ¯ä¸ªå
ç´ 92 return newArray.concat(Array.isArray(item) ? flattenDeep(item) : item) 93 },[])94 }95 function flattenDepth (array, depth = 1) { // æå®éç»´æ°é96 if (depth == 0) {97 return array.slice()98 }99 var newArray = []100 for (var i = 0; i < array.length; i++) {101 var item = array[i] 102 if (Array.isArray(item)) {103 item = flattenDepth(item, depth - 1)104 for (var j = 0; j < item.length; j++) {105 newArray.push(item[j])106 }107 }else {108 newArray.push(item)109 }110 }111 return newArray112 }113 function forEach (collection , f) {114 for (var i = 0; i < collection.length; i++) {115 f(collection[i], i, collection)116 }117 return collection118 }119 function map(array, f) {120 var newArray = []121 for (var i = 0; i < array.length; i++) {122 newArray.push(f(array[i], i)) // pushè¿ä¸ä¸ªæ°çæ°ç»123 }124 return newArray125 }126 function filter (array, f) {127 var newArray = []128 for (var i = 0; i < array.length; i++) {129 if (f(array[i])) {130 newArray.push(array[i])131 }132 }133 return newArray134 }135 function reduce (array, f, initial) {136 for (var i = 0; i < array.length; i++) {137 initial = f(initial, array[i])138 }139 return initial140 }141 function zip (...array) {142 var newArray = []143 var count = array[0].length144 var sum = 0 // æ§å¶éååæ°ç»ç第å 项145 while(count){146 var temporary = []147 for (var i = 0; i < array.length; i++) {148 temporary.push(array[i][sum])149 }150 count--151 sum++152 newArray.push(temporary)153 }154 return newArray155 }156 157 function unzip(array) {158 var newArray = []159 var count = array[0].length160 var sum = 0 // æ§å¶éååæ°ç»ç第å 项161 while(count){162 var temporary = []163 for (var i = 0; i < array.length; i++) {164 temporary.push(array[i][sum])165 }166 count--167 sum++168 newArray.push(temporary)169 }170 return newArray171 }172 function keys (object) { // è¿åkey173 var newArray = []174 if (typeof object == 'object') {175 for (var k in object) {176 newArray.push(k)177 }178 }else {179 var obj = {}180 for (var i = 0; i < object.length; i++) {181 obj[i] = object[i]182 }183 for (var j in obj) {184 newArray.push(j)185 }186 }187 return newArray188 }189 function values(object) { // è¿åå¼190 var newArray = []191 if (typeof(object) == 'object') {192 for (var k of object) {193 newArray.push(k)194 }195 }else{196 for (var i = 0; i < object.length; i++) {197 newArray.push(object[i])198 }199 }200 return newArray201 }202 function difference (array, ...values) {203 var newArray = array.slice()204 values = values.flat()205 values.forEach((x) => {206 newArray.forEach((j,i) => {207 if (x == j) {208 newArray.splice(i,1)209 }210 })211 })212 return newArray213 }214 function differenceBy (array, values = [], f) {215 var newArray = array.slice()216 values = values.flat()217 if (typeof f == 'function') {218 for (let i = 0; i < values.length; i++) {219 values[i] = f(values[i])220 }221 for (let i = 0; i < newArray.length; i++) {222 newArray[i] = f(newArray[i])223 }224 values.forEach((x) => {225 newArray.forEach((j,i) => {226 if (isEqual(x,j)) {227 array.splice(i,1)228 }229 })230 })231 return array232 }233 234 values.forEach((x) => {235 newArray.forEach((j,i) => {236 if (isEqual(x,j)) {237 newArray.splice(i,1)238 }239 })240 })241 return newArray242 }243 function differenceWith (array, values,f) {244 var newArray = array.slice()245 if (typeof f == 'function') {246 for (let i = 0; i < values.length; i++) {247 values[i] = f(values[i])248 }249 for (let i = 0; i < newArray.length; i++) {250 newArray[i] = f(newArray[i])251 }252 values.forEach((x) => {253 newArray.forEach((j,i) => {254 if (isEqual(x,j)) {255 array.splice(i,1)256 }257 })258 })259 return array260 }261 }262 function drop(array, n = 1) {263 var newArray = array.slice()264 for (let i = 0; i < n; i++) {265 newArray.shift()266 }267 return newArray268 }269 function dropRight(array, n = 1) {270 var newArray = array.slice()271 for (let i = 0; i < n; i++) {272 newArray.pop()273 }274 return newArray275 }276 function concat(array,...values) {277 for (let i = 0; i < values.length; i++) {278 if (Array.isArray(values[i])) {279 values[i].forEach(a => array.push(a))280 }else {281 array.push(values[i])282 }283 }284 return array285 } 286 function fill (array, filler, idx = 0, toIdx = array.length) {287 for (let i = idx; i < toIdx; i++) {288 array[i] = filler289 }290 return array291 }292 function head (array) {293 var newArray = array294 return newArray.shift()295 }296 function indexOf (array, value, fromIndex = 0) {297 for (let i = fromIndex; i < array.length; i++) {298 if (value == array[Math.abs(i)]) return Math.abs(i)299 }300 return -1301 }302 303 function initial (array) {304 var newArray = []305 for (let i = 0; i < array.length - 1; i++) {306 newArray.push(array[i])307 }308 return newArray309 }310 function intersection (...array) {311 var newArray = []312 for (let i = 0; i < array[0].length; i++) {313 for (let j = 1; j < array.length; j++) {314 if (!(array[j].includes(array[0][i]))) {315 break // 没æç´æ¥break316 } 317 }318 if (j == array.length) { // å½åé¢ä¸¤ä¸ªæ°ç»é½éåå®æå319 newArray.push(array[0][i])320 }321 return newArray322 }323 } 324 325 return {326 chunk : chunk,327 compact : compact,328 unique : unique,329 flatten : flatten,330 flattenDeep : flattenDeep,331 flattenDepth : flattenDepth,332 forEach : forEach,333 map : map,334 filter : filter,335 reduce : reduce,336 zip : zip,337 unzip : unzip,338 keys : keys,339 values : values,340 difference : difference,341 differenceBy : differenceBy,342 differenceWith : differenceWith,343 drop : drop,344 dropRight : dropRight,345 concat : concat,346 fill : fill,347 head : head,348 indexOf : indexOf,349 intersection : intersection,350 }...
testMatchArray.js
Source:testMatchArray.js
1let arr1 = ['A', 'B', 'C', 'D', 'E']2let arr2 = ['A', 'B', 'C', 'D', 'E']3let arr3 = ['A', 'B', 'C', 'D', 'E']4let arr4 = ['A', 'B', 'C', 'D', 'E']5let arr5 = ['A', 'B', 'C', 'D', 'E']67async function matchArray(arr1, arr2, arr3, arr4, arr5){8 let res = []9 let newArray = ''10 for(let a = 0; a < arr1.length; a++){11 for(let b = 0; b < arr2.length; b++){12 if(arr1[a] === arr2[b]) continue13 for(let c = 0; c < arr3.length; c++){14 if(arr1[a] === arr2[b] || arr1[a] === arr3[c] || arr2[b] === arr3[c]) continue15 for(let d = 0; d < arr4.length; d++){16 if(arr1[a] === arr2[b] || arr1[a] === arr3[c] || arr2[b] === arr3[c] || arr1[a] === arr4[d] || arr2[b] === arr4[d] || arr3[c] === arr4[d]) continue17 for(let e = 0; e < arr5.length; e++){18 if(arr1[a] === arr2[b] || arr1[a] === arr3[c] || arr2[b] === arr3[c] || arr1[a] === arr4[d] || arr2[b] === arr4[d] || arr3[c] === arr4[d] || arr1[a] === arr5[e] || arr2[b] === arr5[e] || arr3[c] === arr5[e] || arr4[d] === arr5[e]) continue19 newArray = [...`${arr1[a]}${arr2[b]}${arr3[c]}${arr4[d]}${arr5[e]}`].sort().toString().replace(/,/g, '')20 if(!res.find(array => array === newArray)) res.push(newArray) 21 newArray = newArray = [...`${arr1[a]}${arr2[b]}${arr3[c]}${arr4[d]}`].sort().toString().replace(/,/g, '')22 if(!res.find(array => array === newArray)) res.push(newArray)23 newArray = [...`${arr1[a]}${arr2[b]}${arr3[c]}${arr5[e]}`].sort().toString().replace(/,/g, '')24 if(!res.find(array => array === newArray)) res.push(newArray)25 newArray = [...`${arr1[a]}${arr2[b]}${arr4[d]}${arr5[e]}`].sort().toString().replace(/,/g, '')26 if(!res.find(array => array === newArray)) res.push(newArray)27 newArray = [...`${arr1[a]}${arr3[c]}${arr4[d]}${arr5[e]}`].sort().toString().replace(/,/g, '')28 if(!res.find(array => array === newArray)) res.push(newArray)29 newArray = [...`${arr2[b]}${arr3[c]}${arr4[d]}${arr5[e]}`].sort().toString().replace(/,/g, '')30 if(!res.find(array => array === newArray)) res.push(newArray)31 newArray = [...`${arr1[a]}${arr2[b]}${arr3[c]}`].sort().toString().replace(/,/g, '')32 if(!res.find(array => array === newArray)) res.push(newArray) 33 newArray = [...`${arr1[a]}${arr2[b]}${arr4[d]}`].sort().toString().replace(/,/g, '')34 if(!res.find(array => array === newArray)) res.push(newArray)35 newArray = [...`${arr1[a]}${arr3[c]}${arr4[d]}`].sort().toString().replace(/,/g, '')36 if(!res.find(array => array === newArray)) res.push(newArray) 37 newArray = [...`${arr2[b]}${arr3[c]}${arr4[d]}`].sort().toString().replace(/,/g, '')38 if(!res.find(array => array === newArray)) res.push(newArray) 39 newArray = [...`${arr1[a]}${arr2[b]}${arr5[e]}`].sort().toString().replace(/,/g, '')40 if(!res.find(array => array === newArray)) res.push(newArray)41 newArray = [...`${arr1[a]}${arr3[c]}${arr5[e]}`].sort().toString().replace(/,/g, '')42 if(!res.find(array => array === newArray)) res.push(newArray) 43 newArray = [...`${arr2[b]}${arr3[c]}${arr5[e]}`].sort().toString().replace(/,/g, '')44 if(!res.find(array => array === newArray)) res.push(newArray)45 newArray = [...`${arr3[c]}${arr4[d]}${arr5[e]}`].sort().toString().replace(/,/g, '')46 if(!res.find(array => array === newArray)) res.push(newArray)47 newArray = [...`${arr1[a]}${arr2[b]}`].sort().toString().replace(/,/g, '')48 if(!res.find(array => array === newArray)) res.push(newArray) 49 newArray = [...`${arr1[a]}${arr3[c]}`].sort().toString().replace(/,/g, '')50 if(!res.find(array => array === newArray)) res.push(newArray)51 newArray = [...`${arr1[a]}${arr4[d]}`].sort().toString().replace(/,/g, '')52 if(!res.find(array => array === newArray)) res.push(newArray) 53 newArray = [...`${arr1[a]}${arr5[e]}`].sort().toString().replace(/,/g, '')54 if(!res.find(array => array === newArray)) res.push(newArray) 55 newArray = [...`${arr2[b]}${arr3[c]}`].sort().toString().replace(/,/g, '')56 if(!res.find(array => array === newArray)) res.push(newArray) 57 newArray = [...`${arr2[b]}${arr3[d]}`].sort().toString().replace(/,/g, '')58 if(!res.find(array => array === newArray)) res.push(newArray)59 newArray = [...`${arr2[b]}${arr3[e]}`].sort().toString().replace(/,/g, '')60 if(!res.find(array => array === newArray)) res.push(newArray) 61 newArray = [...`${arr2[c]}${arr3[d]}`].sort().toString().replace(/,/g, '')62 if(!res.find(array => array === newArray)) res.push(newArray) 63 newArray = [...`${arr2[c]}${arr3[e]}`].sort().toString().replace(/,/g, '')64 if(!res.find(array => array === newArray)) res.push(newArray) 65 newArray = [...`${arr2[d]}${arr3[e]}`].sort().toString().replace(/,/g, '')66 if(!res.find(array => array === newArray)) res.push(newArray) 67 }68 }69 }70 }71 }72 return res73}74 75let handler = async (m, { args, conn, text, usedPrefix }) => {76 let arra = await matchArray(arr1, arr2, arr3, arr4, arr5)77 m.reply(`Total: ${arra.length}78List:79${arra.sort().join('\n')}`) 80}8182handler.help = ['tma']83handler.tags = ['owner']84handler.rowner = true85handler.command = /^tma$/i86
...
Using AI Code Generation
1const fc = require('fast-check');2const newArray = require('fast-check-monorepo').newArray;3fc.assert(4 fc.property(5 fc.integer(0, 100),6 fc.integer(0, 100),7 (len, max) => newArray(len, max).length === len8);
Using AI Code Generation
1const { newArray } = require("fast-check");2newArray(arb, 2, 2).generate(mrng, undefined).value;3 at Object.<anonymous> (test.js:5:16)4 at Module._compile (internal/modules/cjs/loader.js:1158:30)5 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)6 at Module.load (internal/modules/cjs/loader.js:1002:32)7 at Function.Module._load (internal/modules/cjs/loader.js:901:14)8 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
Using AI Code Generation
1import { newArray } from 'fast-check-monorepo';2const myArray = newArray(5);3console.log(myArray);4import { newArray } from 'fast-check-monorepo';5const myArray = newArray(5);6console.log(myArray);7import { newArray } from 'fast-check-monorepo';8const myArray = newArray(5);9console.log(myArray);10import { newArray } from 'fast-check-monorepo';11const myArray = newArray(5);12console.log(myArray);13import { newArray } from 'fast-check-monorepo';14const myArray = newArray(5);15console.log(myArray);16import { newArray } from 'fast-check-monorepo';17const myArray = newArray(5);18console.log(myArray);19import { newArray } from 'fast-check-monorepo';20const myArray = newArray(5);21console.log(myArray);22import { newArray } from 'fast-check-monorepo';23const myArray = newArray(5);24console.log(myArray);25import { newArray } from 'fast-check-monorepo';26const myArray = newArray(5);27console.log(myArray);28import { newArray } from 'fast-check-monorepo';29const myArray = newArray(5);30console.log(myArray);31import { newArray } from 'fast-check-monorepo';32const myArray = newArray(5);33console.log(myArray);34import { newArray } from 'fast-check-monorepo';
Using AI Code Generation
1const fc = require('fast-check');2const newArray = require('fast-check-monorepo').newArray;3const fc = require('fast-check-monorepo');4const newArray = fc.newArray;5const newArray = require('fast-check').newArray;6- Writing code (**no pull request is too small**: fix typos, add comments, clean up inconsistent whitespace)7Please read our [CONTRIBUTING.md](
Using AI Code Generation
1import { newArray } from 'fast-check-monorepo';2const arr = newArray(3);3console.log(arr);4import { newArray } from 'fast-check';5const arr = newArray(3);6console.log(arr);7import { newArray } from 'fast-check-monorepo';8const arr = newArray(3);9console.log(arr);10import { newArray } from 'fast-check';11const arr = newArray(3);12console.log(arr);13import { newArray } from 'fast-check-monorepo';14const arr = newArray(3);15console.log(arr);16import { newArray } from 'fast-check';17const arr = newArray(3);18console.log(arr);19import { newArray } from 'fast-check-monorepo';20const arr = newArray(3);21console.log(arr);22import { newArray } from 'fast-check';23const arr = newArray(3);24console.log(arr);25import { newArray } from 'fast-check-monorepo';26const arr = newArray(3);27console.log(arr);28import { newArray } from 'fast-check';29const arr = newArray(3);30console.log(arr);
Using AI Code Generation
1const newArray = require('fast-check-monorepo').newArray;2const fc = require('fast-check');3const assert = require('assert');4const testArray = newArray(fc.nat(), 100);5console.log(testArray);6const newArray = require('fast-check-monorepo').newArray;7const fc = require('fast-check');8const assert = require('assert');9const testArray = newArray(fc.nat(), 100);10console.log(testArray);11const newArray = require('fast-check-monorepo').newArray;12const fc = require('fast-check');13const assert = require('assert');14const testArray = newArray(fc.nat(), 100);15console.log(testArray);16const newArray = require('fast-check-monorepo').newArray;17const fc = require('fast-check');18const assert = require('assert');19const testArray = newArray(fc.nat(), 100);20console.log(testArray);21const newArray = require('fast-check-monorepo').newArray;22const fc = require('fast-check');23const assert = require('assert');24const testArray = newArray(fc.nat(), 100);25console.log(testArray);26const newArray = require('fast-check-monorepo').newArray;27const fc = require('fast-check');28const assert = require('assert');29const testArray = newArray(fc.nat(), 100);30console.log(testArray);31const newArray = require('fast-check-monorepo').newArray;32const fc = require('fast-check');33const assert = require('assert');34const testArray = newArray(fc.nat(), 100);35console.log(testArray);36const newArray = require('fast-check-monorepo').newArray;37const fc = require('fast-check');38const assert = require('assert');39const testArray = newArray(fc.nat(), 100);40console.log(testArray);41const newArray = require('fast-check-monorepo').newArray;42const fc = require('fast-check');
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!