Best JavaScript code snippet using wpt
constant_data.js
Source:constant_data.js
1var json_config_file=require("./json_config_file");2var log_data=require("./log_data");3var log_data_logic=require("./help_log_data_logic");45var ConstValue=function()6{7 /*éå¨Excel表ä¸é
ç½®ç常é*/8 //å级ä½åä¸éå¢å æ°é9 this.STAMINA_ADD = 0;10 //åå§å¥½åä¸é11 this.FRIEND_INIT_LIMIT = [];12 //å个好åæ¯æ¥ä½¿ç¨æ¬¡æ°éå¶13 this.FRIEND_USE_TIMES = 0;14 //æ¦å°ç©ºé´åå§ä¸é15 this.CARD_BAG_LIMIT = 0;16 //æ¯æ¬¡æ©å
æ¦å°èå
ä¸é17 this.BAG_EXPEND_LIMIT=0;18 //æ©å
æ¦å°èå
æ¶èå
å®19 this.BAG_EXPAND_COST = 0;20 //ä½åæ¢å¤æ¶é´21 this.POINT_TICK = 0;22 //ä½åæ大å¼23 this.STAMINA_MAX = 0;24 //æåé请好åæ°é25 this.FIGHT_FRIEND_NUM = 0;26 //é请好å人è·å¾ç§¯å27 this.FRIEND_SCORE = 0;28 //é请éç人è·å¾ç§¯å29 this.USER_SCORE = 0;30 //补满æ¢ç´¢ä¸ªæ°è±è´¹31 this.EXPLORE_COST = [];32 //åå§æ¢ç´¢ä¸é33 this.EXPLORE_INIT_LIMIT = 0;34 //æ¢ç´¢æ¢å¤æ¶é´35 this.EXPLORE_TICK=0;36 //åè¿æ½ææ£37 this.RECRUIT_DISCOUNT=0;38 //æå¡39 this.CD_REWARD_TIME=0;404142 //强åæ¦å°ç»éªéé±åæ°43 this.Up_CARD_COST_MONEY_RATIO=0;44 //è天å
费次æ°45 this.CHAT_FREE_TIMES=0;46 //è天è±è´¹RMB47 this.CHAT_COST=0;48 //å鸡å¢å ä½å49 this.CHICK_ADD=0;50 //å
æ¢åºå计æ¶(毫ç§å¼)51 this.EXCHANGE_MS=0;52 //å
æ¢åºå·æ°è±è´¹53 this.EXCHANGE_COST=0;54 //转çç级éå¶55 this.REBORN_LEVEL=[];56 //æ¢ç´¢å¼å¯ç级57 this.EXPLORE_LEVEL=0;58 //å级æ¢å¤ä½å59 this.UP_ADD_POWER=0;60 //æé±æ è·åçéé±61 this.MT_GOLD=0;62 //æé±è±è´¹63 this.MT_COST=[];64 //æé±æ VIP次æ°65 this.MT_VIP_TIMES=[];66 //æé±æ ä½çº§æ´å»æ¦ç67 this.MT_Crit_LOW=0;68 //æé±æ é«çº§æ´å»æ¦ç69 this.MT_Crit_HIGH=0;70 //é¸ä¸éé±å¥å±71 this.TOWN_COIN_REWARD=0;72 //çç«å¡å
ID73 this.PANDA_ITEM_ID=0;74 //è¥çªå¡å
ID75 this.PIG_ITEM_ID=0;76 //çç«å¡çID77 this.PANDA_CARD_ID=0;78 //è¥çªå¡çID79 this.PIG_CARD_ID=0;80 //éç½®æ«è¡è±è´¹81 this.RESET_SWEEP_COST=[];82 //VIP对åºçå
å¼é¢åº¦83 this.VIP=[];84 //ææå¤æ´»è±è´¹85 this.REVIVE_COST=[];86 //ææå¤æ´»VIP次æ°87 this.REVIVE_TIMES=[];88 //转çè±è´¹éé±89 this.REBORN_COST=[];90919293 /*éå¨Excel表ä¸é
ç½®ç常é*/949596 /*ç¨åºèªå®ä¹å¸¸é*/9798 //æ大é®ä»¶æ°é99 this.MAIL_MAX=30;100101 //æ¦å°ç¶æ102 this.CARD_STATUS_OFF=1;//ä¸éµ103 this.CARD_STATUS_ON=2;//ä¸éµ104 this.CARD_STATUS_LEADER=3;//ç»å¸
105 this.CARD_STATUS_VAN=4;//å
é106 this.CARD_STATUS_GUARD=5;//åå®107108 //å¥å±åç±»109 this.REWARD_TYPE_CARD=1;//å¡ç110 this.REWARD_TYPE_SOUL=2;//éé111 this.REWARD_TYPE_ITEM=3;//éå
·112 this.REWARD_TYPE_RMB=4;//人æ°å¸113 this.REWARD_TYPE_MONEY=5;//游æå¸114 this.REWARD_TYPE_SCORE=6;//积å115 this.REWARD_TYPE_EXP=7;//ç»éª116 this.REWARD_TYPE_POINT=8;//ä½å117118 //éå
·åç±»119 this.ITEM_TYPE_BOX=1;//å®ç®±120 this.ITEM_TYPE_KEY=2;//é¥å121 this.ITEM_TYPE_STAMINA=3;//å
å122 this.ITEM_TYPE_EQUIP=4;//è£
å¤123 this.ITEM_TYPE_EQUIP_FRAG=5;//è£
å¤ç¢ç124125 //å¡çè£
å¤ä¸é126 this.CARD_EQUIP_LIMIT=3;127128 //å
³å¡ææåç±»129 this.FIGHT_TYPE_GATE=1; //æ®éå
³å¡ææ130 this.FIGHT_TYPE_TOWN=2; //åæ± ææï¼ææï¼131 this.FIGHT_TYPE_BATTLE=3; //æåºææï¼æ´»å¨ï¼132133 //å¡çèå
æ大éå¶134 this.CARD_BAG_MAX_LIMIT=200;135136 //æ就类å137 this.ACHI_TYPE_GATE=1; //éå
³å
³å¡138 //this.ACHI_TYPE_RECHARGE_TIMES=2; //å
å¼æ¬¡æ°139 //this.ACHI_TYPE_RECHARGE_SUM=3; //å
å¼éé¢140 this.ACHI_TYPE_EXPLORE_TIMES=4; //æ¢ç´¢æ¬¡æ°141 //this.ACHI_TYPE_BUY_EXPLORE=5; //è¡¥å
æ¢ç´¢æ¬¡æ°142 //this.ACHI_TYPE_LOGIN=7; //è¿ç»ç»å½å¤©æ°143 //this.ACHI_TYPE_SKILL_VAN=8; //å
éæè½æ¬¡æ°144 //this.ACHI_TYPE_NINE=10; //ä¹è¿éæ¾æ¬¡æ°145 this.ACHI_TYPE_KILL_NUM=11; //å»ææ°é146 this.ACHI_TYPE_LEVEL=12; //ç©å®¶ç级147 this.ACHI_TYPE_CARD_STAR=13; //5æ级æ¦å°æ°é148 this.ACHI_TYPE_EQUIP_NUM=14; //è£
å¤è·å¾æ°é149 this.ACHI_TYPE_CARD_EVOLVE_COUNT=15; //转ççæ¦å°ä¸ªæ°150 this.ACHI_TYPE_CARD_EVOLVE_LEVEL=16; //转ççæ¦å°ç级151 //this.ACHI_TYPE_GRIFFIN=17; //ææä¸å¬å¤ç¥å
½æ¬¡æ°152 //this.ACHI_TYPE_TOWNS=18; //å é¢åæ± æ°é153 this.ACHI_TYPE_TOWNS_FIGHT=19; //é¸ä¸ææ次æ°154155156 this.EXCHANGE_LIST_NUM=5;//å
æ¢å表æ°é157158 //é®ä»¶ç±»å159 this.MAIL_TYPE_REWARD=1;//å¯ä»¥é¢åå¥å±çé®ä»¶160 this.MAIL_TYPE_READ_SUCC=2;//æå é¢äºåæ± ,åªè¯»161 this.MAIL_TYPE_READ_FAIL=3;//æçåæ± è¢«å¤ºèµ°ï¼åªè¯»162163 //åæ± ç¶æ164 this.TOWN_STATUS_INIT=1;//åå§ç¶æ165 this.TOWN_STATUS_CARD=2;//å
³å¡éå
³ æ¦å°æªé¢å166 this.TOWN_STATUS_BEAUTY=3;//ç¾å¥³æªé¢å167 this.TOWN_STATUS_OK=4;//éå
³168169 //æé±æ ä½çº§æ´å»è§¦åè·å¾åç170 this.MT_LOW_GAIN=1.5;171 //æé±æ é«çº§æ´å»è§¦åè·å¾åç172 this.MT_HIGH_GAIN=2;173174 /*ç¨åºèªå®ä¹å¸¸é*/175176};177178var const_value=new ConstValue();179exports.const_value=const_value;180181182function init()183{184 load_constant_data();185}186exports.init=init;187188function load_constant_data()189{190 global.log("load_constant_data");191 var file="const.json";192 var data=json_config_file.json_config_file_list[file];193194 var ks=Object.keys(data["CONST"]);195 var count=ks.length;196 //å®ç°å®å
¨æ·è´197 for(var i=1 ; i<=count ; i++)198 {199 const_value.STAMINA_ADD=Number(data["CONST"][i].StaminaAdd);200201 (data["CONST"][i].FriendInitLimit).split(',').forEach(function(e){202 const_value.FRIEND_INIT_LIMIT.push(Number(e));203 });204205 const_value.FRIEND_USE_TIMES=Number(data["CONST"][i].EveryFirendUseTimes);206 const_value.CARD_BAG_LIMIT=Number(data["CONST"][i].CardBagLimit);207 const_value.BAG_EXPEND_LIMIT=Number(data["CONST"][i].BagExpandLimit);208 const_value.BAG_EXPAND_COST=Number(data["CONST"][i].BagExpandCost);209 const_value.POINT_TICK= Number(data["CONST"][i].Point_Tick);210 const_value.STAMINA_MAX= Number(data["CONST"][i].StaminaMax);211 const_value.FIGHT_FRIEND_NUM= Number(data["CONST"][i].FightFriendNum);212 const_value.FRIEND_SCORE= Number(data["CONST"][i].FriendScore);213 const_value.USER_SCORE= Number(data["CONST"][i].UserScore);214 const_value.TOWN_COIN_REWARD= Number(data["CONST"][i].TownRewardCoin);215 (data["CONST"][i].ExploreCost).split(',').forEach(function(e){216 const_value.EXPLORE_COST.push(Number(e));217 });218 const_value.EXPLORE_INIT_LIMIT= Number(data["CONST"][i].ExploreInitLimit);219 const_value.EXPLORE_TICK= Number(data["CONST"][i].ExploreTick);220 const_value.RECRUIT_DISCOUNT= Number(data["CONST"][i].RecruitDiscount);221 const_value.CD_REWARD_TIME= Number(data["CONST"][i].CdRewardTime);222 const_value.Up_CARD_COST_MONEY_RATIO= Number(data["CONST"][i].UpWarriorCostMoneyRatio);223 const_value.CHAT_FREE_TIMES= Number(data["CONST"][i].ChatFreeTimes);224 const_value.CHAT_COST= Number(data["CONST"][i].ChatCost);225 const_value.CHICK_ADD= Number(data["CONST"][i].ChickAdd);226 const_value.EXCHANGE_MS= Number(data["CONST"][i].ExchangeHour)*60*60*1000;227 const_value.EXCHANGE_COST= Number(data["CONST"][i].ExchangeCost);228229230 (data["CONST"][i].RebornLevel).split(',').forEach(function(e){231 const_value.REBORN_LEVEL.push(Number(e));232 });233 const_value.EXPLORE_LEVEL= Number(data["CONST"][i].ExploreLv);234 const_value.UP_ADD_POWER= Number(data["CONST"][i].UpGradePower);235 const_value.MT_GOLD= Number(data["CONST"][i].MTGold);236 (data["CONST"][i].MTCost).split(',').forEach(function(e){237 const_value.MT_COST.push(Number(e));238 });239240 (data["CONST"][i].MTVipTimes).split(',').forEach(function(e){241 const_value.MT_VIP_TIMES.push(Number(e));242 });243 const_value.MT_Crit_LOW= Number(data["CONST"][i].MTCritLow)*10;244 const_value.MT_Crit_HIGH= Number(data["CONST"][i].MTCritHigh)*10+const_value.MT_Crit_LOW;245 const_value.PANDA_ITEM_ID= data["CONST"][i].PandaItemId;246 const_value.PIG_ITEM_ID= data["CONST"][i].PigItemId;247 const_value.PANDA_CARD_ID= data["CONST"][i].PandaCardId;248 const_value.PIG_CARD_ID= data["CONST"][i].PigCardId;249250 (data["CONST"][i].ResetSweepCost).split(',').forEach(function(e){251 const_value.RESET_SWEEP_COST.push(Number(e));252 });253254 (data["CONST"][i].Vip).split(',').forEach(function(e){255 const_value.VIP.push(Number(e));256 });257258 (data["CONST"][i].ReviveCost).split(',').forEach(function(e){259 const_value.REVIVE_COST.push(Number(e));260 });261262 (data["CONST"][i].ReviveTimes).split(',').forEach(function(e){263 const_value.REVIVE_TIMES.push(Number(e));264 });265266 (data["CONST"][i].RebornCost).split(',').forEach(function(e){267 const_value.REBORN_COST.push(Number(e));268 });269270 break;271 }272273 var log_content={"count":count,"const_value":const_value};274 var logData=log_data_logic.help_create_log_data("sys","sys","sys","sys","sys","load_constant_data",log_content,log_data.logType.LOG_CONFIG);275 log_data_logic.log(logData);276277}
...
analysis.js
Source:analysis.js
1var fs = require('fs');2var readline = require('readline');3const CONST_VALUE = '1';4function analysis() {5 fs.readFile('/Users/sexychen/myFile/work/console/car/data.json', "utf8", function (err, data) {6 if (!data) {7 console.error('data is null');8 return;9 }10 var jsonData = JSON.parse(data);11 if (!jsonData || jsonData.length <= 0) {12 console.error('parse json error');13 return;14 }15 replaceImgPath(jsonData)16 // extractBrand(jsonData);17 // filterPrice(jsonData);18 });19}20// æ¿æ¢logoå车身å¤è§çå¾çå°å为线ä¸çå°å21function replaceImgPath(jsonData) {22 // logoæ件: /Users/sexychen/myFile/work/console/car/logo_name23 var logoNameMap = {};24 var fRead = fs.createReadStream('/Users/sexychen/myFile/work/console/car/logo_name');25 var objReadline = readline.createInterface({26 input: fRead27 });28 objReadline.on('line',function (line) {29 logoNameMap[line] = CONST_VALUE;30 });31 objReadline.on('close',function () {32 readAppearanceName(logoNameMap, jsonData);33 });34}35function readAppearanceName(logoNameMap, jsonData) {36 // å¤è§æ件: /Users/sexychen/myFile/work/console/car/appearance_name37 var appearanceNameMap = {};38 var fRead2 = fs.createReadStream('/Users/sexychen/myFile/work/console/car/appearance_name');39 var objReadline2 = readline.createInterface({40 input: fRead241 });42 objReadline2.on('line',function (line) {43 appearanceNameMap[line] = CONST_VALUE44 });45 objReadline2.on('close',function () {46 doReplace(logoNameMap, appearanceNameMap, jsonData);47 });48}49function doReplace(logoNameMap, appearanceNameMap, jsonData){50 // å¤ææºæ°æ®çæ¯å¦åå¨logoå车身å¤è§ççå®æ件51 for (let index = 0; index < jsonData.length; index++) {52 var car = jsonData[index];53 var logoSmallName = car.bCode + '_1';54 var logoLargeName = car.bCode + '_2';55 // åå¨logo大å¾56 if (logoNameMap[logoLargeName] === CONST_VALUE) {57 car.logo = 'https://img.117sport.com/miniprogram/car/garage/logo/' + logoLargeName + '.jpg';58 }59 // åªæå°å¾,åæ¶æ个æ 60 else if (logoNameMap[logoSmallName] === CONST_VALUE){61 car.logo = 'https://img.117sport.com/miniprogram/car/garage/logo/' + logoSmallName + '.jpg';62 car.sLogo = true;63 }64 // æ¯ä¸ªè½¦ç³»è½¦èº«å¤è§çå¤ç65 var series = car.series;66 for (let index = 0; index < series.length; index++) {67 const carSeries = series[index];68 carSeries.imgs = [];69 // ä¸å¼ å¾70 var first = carSeries.sCode + '_1';71 if (appearanceNameMap[first] === CONST_VALUE) {72 carSeries.imgs.push({73 path: 'https://img.117sport.com/miniprogram/car/garage/appearance/' + first + '.jpg'74 })75 }76 var second = carSeries.sCode + '_2';77 if (appearanceNameMap[second] === CONST_VALUE) {78 carSeries.imgs.push({79 path: 'https://img.117sport.com/miniprogram/car/garage/appearance/' + second + '.jpg'80 })81 }82 var third = carSeries.sCode + '_3';83 if (appearanceNameMap[third] === CONST_VALUE) {84 carSeries.imgs.push({85 path: 'https://img.117sport.com/miniprogram/car/garage/appearance/' + third + '.jpg'86 })87 }88 // æ¸
é¤ä¸éè¦çæ°æ®89 carSeries.img1 = undefined;90 carSeries.img2 = undefined;91 carSeries.img3 = undefined;92 carSeries.page = undefined;93 }94 }95 // éæ°æ个åº96 var newJsonData = []97 jsonData.forEach(element => {98 newJsonData.push({99 char: element.char,100 bCode: element.bCode,101 bName: element.bName,102 sLogo: element.sLogo,103 logo: element.logo,104 bMinP: element.bMinP,105 bMaxP: element.bMaxP,106 series: element.series107 });108 });109 // ä¿åæ¿æ¢ä¹åçjson110 fs.writeFileSync('/Users/sexychen/myFile/work/console/car/data_replace_img.json', JSON.stringify(newJsonData));111}112// 转æ¢æç¹å®çæ ¼å¼113function extractBrand(jsonData) {114 var data = [];115 for (let index = 0; index < jsonData.length; index++) {116 var car = jsonData[index];117 data.push({118 bName: car.bName,119 bCode: car.bCode120 })121 }122 fs.writeFileSync('/Users/sexychen/myFile/work/console/car/convert.json', JSON.stringify(data))123}124// è¿æ»¤ä»·æ ¼125function filterPrice(jsonData) {126 for (let index = 0; index < jsonData.length; index++) {127 var car = jsonData[index];128 // if (car.bMaxP && car.bMaxP >= 100 && car.bMinP && car.bMinP >= 30) {129 if (!car.bMaxP && !car.bMinP && car.bName.match(/^[a-zA-Z]+/)) {130 console.error(car.bName + ': ' + car.series[0].page);131 }132 }133}...
640.求解方程.js
Source:640.求解方程.js
1var solveEquation = function (equation) {2 let xishu = 0;3 let const_value = 0;4 equation = equation.replaceAll("-", "+-");5 let [left, right] = equation.split('=');6 left = left.split("+"); //å·²å å·åå²ï¼å¦æå
å«x,å7 for (let item of left) {8 if (item !== "") {9 if (item.includes("x")) {10 // å
å«xç项11 if (item === "x") {12 xishu += 1;13 } else {14 xishu += +item.split("x")[0];15 }16 } else {17 const_value -= parseInt(item);18 }19 }20 }21 right = right.split("+");22 for (let item of right) {23 if (item !== "") {24 if (item.includes("x")) {25 if (item === "x") {26 xishu -= 1;27 } else {28 xishu -= +item.split("x")[0];29 }30 // å
å«xç项31 } else {32 const_value += parseInt(item);33 }34 }35 }36 if (xishu === 0) {37 if (const_value === 0) {38 return "Infinite solutions"39 } else {40 return "No solution"41 }42 }43 let value = parseInt(const_value / xishu);44 return "x=" + value;45};...
Using AI Code Generation
1const wpt = require('webpagetest');2const wptInstance = wpt('API_KEY');3}, function(err, data) {4 if (err) return console.error(err);5 console.log('testId', data.data.testId);6 console.log('ownerKey', data.data.ownerKey);7 wptInstance.getTestResults(data.data.testId, data.data.ownerKey, function(err, data) {8 if (err) return console.error(err);9 console.log('data', data);10 });11});
Using AI Code Generation
1const { const_value } = require('./wpt');2console.log(const_value);3const { wpt } = require('./wpt');4console.log(wpt);5const { get } = require('./wpt');6console.log(get());7const { set } = require('./wpt');8console.log(set(10));9const { add } = require('./wpt');10console.log(add(10));11const { sub } = require('./wpt');12console.log(sub(10));
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!!