How to use swapped method in wpt

Best JavaScript code snippet using wpt

argumentParser.js

Source:argumentParser.js Github

copy

Full Screen

1const parseArgs = async (ctx, args) => {2 if (args.length === 0) {3 return false4 }5 let starts = ['add', 'enable', 'start', 'true']6 let stops = ['stop', 'disable', 'false', 'remove']7 const newArgs = {8 ids: [],9 start: false,10 stop: false,11 extra: []12 }13 args.map(x => {14 switch (x) {15 case 'add':16 case 'enable':17 case 'start':18 case 'true':19 newArgs.start = true20 break21 case 'stop':22 case 'disable':23 case 'false':24 case 'remove':25 newArgs.stop = true26 break27 default:28 let ID = tryGetUserID(x)29 if (ID){30 newArgs.ids.push(ID)31 } else {32 newArgs.extra.push(x)33 }34 }35 })36 return newArgs37}38const strictLogArgs = async (ctx, log, enable, ...args) => {39 if (args.length === 0) {40 return false41 }42 let swapped = {43 swapped: [],44 not_found: []45 }46 args.map(x => {47 switch (x) {48 case 'guild_update':49 swapped.swapped.push("Guild Update")50 log.guild_events.update = enable51 break52 case 'invites':53 swapped.swapped.push("Invite Events")54 log.guild_events.invites = enable55 break56 case 'channel_create':57 swapped.swapped.push("Channel Create")58 log.channel_events.create = enable59 break60 case 'channel_delete':61 swapped.swapped.push("Channel Delete")62 log.channel_events.delete = enable63 break64 case 'channel_update':65 swapped.swapped.push("Channel Updates")66 log.channel_events.update = enable67 break68 case 'channel_pin_update':69 swapped.swapped.push("Channel Pin Update")70 log.channel_events.pins = enable71 break72 case 'avatar_change':73 swapped.swapped.push("Avatar Change")74 log.user_events.avatar = enable75 break76 case 'username_change':77 swapped.swapped.push("Username Change")78 log.user_events.username = enable79 break80 case 'discriminator_change':81 swapped.swapped.push("Discriminator Change")82 log.user_events.discriminator = enable83 break84 case 'member_join':85 swapped.swapped.push("Member Join")86 log.member_events.add = enable87 break88 case 'member_update':89 case 'member_updates':90 swapped.swapped.push("Member Updates")91 log.member_events.update = enable92 break93 case 'member_leave':94 swapped.swapped.push("Member Leave")95 log.member_events.remove = enable96 break97 case 'presence_update':98 swapped.swapped.push("Presence Updates")99 log.member_events.presence = enable100 break101 case 'join_channel':102 swapped.swapped.push("Voice Channel Join")103 log.voice_events.join = enable104 break105 case 'switch_channel':106 swapped.swapped.push("Voice Channel Switch")107 log.voice_events.switch = enable108 break109 case 'leave_channel':110 swapped.swapped.push("Voice Channel Leave")111 log.voice_events.leave = enable112 break113 case 'voice_state':114 swapped.swapped.push("Voice State")115 log.voice_events.state = enable116 break117 case 'role_create':118 swapped.swapped.push("Role Create")119 log.role_events.create = enable120 break121 case 'role_delete':122 swapped.swapped.push("Role Delete")123 log.role_events.delete = enable124 break125 case 'role_update':126 swapped.swapped.push("Role Update")127 log.role_events.update = enable128 break129 case 'channel_events':130 swapped.swapped.push("All Channel Events")131 log.channel_events.all = enable132 break133 case 'guild_events':134 swapped.swapped.push("All Guild Events")135 log.guild_events.all = enable136 break137 case 'member_events':138 swapped.swapped.push("All Member Events")139 log.member_events.all = enable140 break141 case 'user_events':142 swapped.swapped.push("All User Events")143 log.user_events.all = enable144 break145 case 'role_events':146 swapped.swapped.push("All Role Events")147 log.role_events.all = enable148 break149 case 'voice_events':150 swapped.swapped.push("All Voice Events")151 log.voice_events.all = enable152 break153 default:154 swapped.not_found.push(x)155 }156 })157 await log.save()158 return swapped159}160const looseLogArgs = async (ctx, log, args) => {161 if (args.length === 0) {162 return false163 }164 let swapped = {165 enabled: [],166 disabled: [],167 not_found: []168 }169 args.map(x => {170 switch (x) {171 case 'guild_update':172 log.guild_events.update? swapped.disabled.push(x): swapped.enabled.push(x)173 log.guild_events.update = !log.guild_events.update174 break175 case 'invites':176 log.guild_events.invites? swapped.disabled.push(x): swapped.enabled.push(x)177 log.guild_events.invites = !log.guild_events.invites178 break179 case 'channel_create':180 log.channel_events.create? swapped.disabled.push(x): swapped.enabled.push(x)181 log.channel_events.create = !log.channel_events.create182 break183 case 'channel_delete':184 log.channel_events.delete? swapped.disabled.push(x): swapped.enabled.push(x)185 log.channel_events.delete = !log.channel_events.delete186 break187 case 'channel_update':188 log.channel_events.update? swapped.disabled.push(x): swapped.enabled.push(x)189 log.channel_events.update = !log.channel_events.update190 break191 case 'channel_pin_update':192 log.channel_events.pins? swapped.disabled.push(x): swapped.enabled.push(x)193 log.channel_events.pins = !log.channel_events.pins194 break195 case 'avatar_change':196 log.user_events.avatar? swapped.disabled.push(x): swapped.enabled.push(x)197 log.user_events.avatar = !log.user_events.avatar198 break199 case 'username_change':200 log.user_events.username? swapped.disabled.push(x): swapped.enabled.push(x)201 log.user_events.username = !log.user_events.username202 break203 case 'discriminator_change':204 log.user_events.discriminator? swapped.disabled.push(x): swapped.enabled.push(x)205 log.user_events.discriminator = !log.user_events.discriminator206 break207 case 'member_join':208 log.member_events.join? swapped.disabled.push(x): swapped.enabled.push(x)209 log.member_events.join = !log.member_events.join210 break211 case 'member_update':212 log.member_events.update? swapped.disabled.push(x): swapped.enabled.push(x)213 log.member_events.update = !log.member_events.update214 break215 case 'member_leave':216 log.member_events.leave? swapped.disabled.push(x): swapped.enabled.push(x)217 log.member_events.leave = !log.member_events.leave218 break219 case 'presence_update':220 log.member_events.presence? swapped.disabled.push(x): swapped.enabled.push(x)221 log.member_events.presence = !log.member_events.presence222 break223 case 'join_channel':224 log.voice_events.join? swapped.disabled.push(x): swapped.enabled.push(x)225 log.voice_events.join = !log.voice_events.join226 break227 case 'switch_channel':228 log.voice_events.switch? swapped.disabled.push(x): swapped.enabled.push(x)229 log.voice_events.switch = !log.voice_events.switch230 break231 case 'leave_channel':232 log.voice_events.leave? swapped.disabled.push(x): swapped.enabled.push(x)233 log.voice_events.leave = !log.voice_events.leave234 break235 case 'voice_state':236 log.voice_events.state? swapped.disabled.push(x): swapped.enabled.push(x)237 log.voice_events.state = !log.voice_events.state238 break239 case 'role_create':240 log.role_events.create? swapped.disabled.push(x): swapped.enabled.push(x)241 log.role_events.create = !log.role_events.create242 break243 case 'role_delete':244 log.role_events.delete? swapped.disabled.push(x): swapped.enabled.push(x)245 log.role_events.delete = !log.role_events.delete246 break247 case 'role_update':248 log.role_events.update? swapped.disabled.push(x): swapped.enabled.push(x)249 log.role_events.update = !log.role_events.update250 break251 case 'channel_events':252 log.channel_events.all? swapped.disabled.push(x): swapped.enabled.push(x)253 log.channel_events.all = !og.channel_events.all254 break255 case 'guild_events':256 log.guild_events.all? swapped.disabled.push(x): swapped.enabled.push(x)257 log.guild_events.all = !log.guild_events.all258 break259 case 'member_events':260 log.member_events.all? swapped.disabled.push(x): swapped.enabled.push(x)261 log.member_events.all = !log.member_events.all262 break263 case 'user_events':264 log.user_events.all? swapped.disabled.push(x): swapped.enabled.push(x)265 log.user_events.all = !log.user_events.all266 break267 case 'role_events':268 log.role_events.all? swapped.disabled.push(x): swapped.enabled.push(x)269 log.role_events.all = !log.role_events.all270 break271 case 'voice_events':272 log.voice_events.all? swapped.disabled.push(x): swapped.enabled.push(x)273 log.voice_events.all = !log.voice_events.all274 break275 default:276 swapped.not_found.push(x)277 }278 })279 return swapped280}281const tryGetUserID = (inp) => {282 inp = inp.trim()283 try {284 if (/^\d+$/.test(inp) && inp > (1000 * 60 * 60 * 24 * 30 * 2 ** 22)){285 return inp;286 } else {287 return inp.slice(0, -1).split('@')[1].replace('!', '').replace('&', '');288 }289 }290 catch(err) { }291 return false292}293module.exports = {294 looseLogArgs,295 parseArgs,296 strictLogArgs...

Full Screen

Full Screen

serialization.ts

Source:serialization.ts Github

copy

Full Screen

1import {expect} from "assertions"2import * as ser from "@bokehjs/core/util/serialization"3import {ndarray} from "@bokehjs/core/util/ndarray"4const GOOD_TYPES = [5 Float32Array, Float64Array, Uint8Array, Int8Array,6 Uint16Array, Int16Array, Uint32Array, Int32Array,7]8describe("serialization module", () => {9 describe("BYTE_ORDER", () => {10 it("should be big or little", () => {11 // not a great test but the best we can do for now12 const o = ser.BYTE_ORDER13 expect(o == "big" || o == "little").to.be.true14 })15 })16 describe("byte swap functions", () => {17 it("should have swap16 that swaps 2 bytes in place", () => {18 const a = new Uint8Array(4)19 for (let i = 0; i < 4; i++) {20 a[i] = i21 }22 const b = new Uint16Array(a.buffer)23 expect(b.length).to.be.equal(2)24 const swapped = new Uint8Array(4)25 swapped[0] = 126 swapped[1] = 027 swapped[2] = 328 swapped[3] = 229 ser.swap16(b)30 expect(a).to.be.equal(swapped)31 })32 it("should have swap32 that swaps 4 bytes in place", () => {33 const a = new Uint8Array(8)34 for (let i = 0; i < 8; i++) {35 a[i] = i36 }37 const b = new Float32Array(a.buffer)38 expect(b.length).to.be.equal(2)39 const swapped = new Uint8Array(8)40 swapped[0] = 341 swapped[1] = 242 swapped[2] = 143 swapped[3] = 044 swapped[4] = 745 swapped[5] = 646 swapped[6] = 547 swapped[7] = 448 ser.swap32(b)49 expect(a).to.be.equal(swapped)50 })51 it("should have swap64 that swaps 8 bytes in place", () => {52 const a = new Uint8Array(16)53 for (let i = 0; i < 16; i++) {54 a[i] = i55 }56 const b = new Float64Array(a.buffer)57 expect(b.length).to.be.equal(2)58 const swapped = new Uint8Array(16)59 swapped[0] = 760 swapped[1] = 661 swapped[2] = 562 swapped[3] = 463 swapped[4] = 364 swapped[5] = 265 swapped[6] = 166 swapped[7] = 067 swapped[8] = 1568 swapped[9] = 1469 swapped[10] = 1370 swapped[11] = 1271 swapped[12] = 1172 swapped[13] = 1073 swapped[14] = 974 swapped[15] = 875 ser.swap64(b)76 expect(a).to.be.equal(swapped)77 })78 })79 describe("base64 conversion functions", () => {80 for (const typ of GOOD_TYPES) {81 it(`should round trip ${typ.name} buffers`, () => {82 const a = new Uint8Array(16)83 for (let i = 0; i < 16; i++) {84 a[i] = i85 }86 const b = new typ(a)87 const b64 = ser.buffer_to_base64(b.buffer)88 expect(typeof b64).to.be.equal("string")89 const buf = ser.base64_to_buffer(b64)90 const c = new typ(buf)91 expect(c).to.be.equal(b)92 })93 }94 })95 it("should support NDArray serialization and de-serialization", () => {96 const nd0 = ndarray([1, 2, 3, 4, 5, 6], {dtype: "int32", shape: [2, 3]})97 const buffers0 = new Map<string, ArrayBuffer>()98 const ref0_0 = ser.encode_NDArray(nd0, buffers0)99 expect(ref0_0).to.be.equal({100 __buffer__: "0",101 order: ser.BYTE_ORDER,102 dtype: "int32",103 shape: [2, 3],104 })105 expect(buffers0).to.be.equal(new Map([["0", nd0.buffer]]))106 const deref0_0 = ser.decode_NDArray(ref0_0, buffers0)107 expect(deref0_0).to.be.equal(nd0)108 expect(() => ser.decode_NDArray(ref0_0, new Map())).to.throw()109 const ref0_1 = ser.encode_NDArray(nd0)110 expect(ref0_1).to.be.equal({111 __ndarray__: "AQAAAAIAAAADAAAABAAAAAUAAAAGAAAA",112 order: ser.BYTE_ORDER,113 dtype: "int32",114 shape: [2, 3],115 })116 const deref0_1 = ser.decode_NDArray(ref0_1, new Map())117 expect(deref0_1).to.be.equal(nd0)118 })...

Full Screen

Full Screen

1.冒泡排序.js

Source:1.冒泡排序.js Github

copy

Full Screen

1const { swap } = require('./util')2// $ i表示的是需要执行的遍历次数,以及最少能保证最后i个元素是有序的3// $ j表示在依次对数组进行遍历,且执行交换4/* function bubbleSort(arr) {5 for(let i = 0; i < arr.length; i++){6 for(let j = 0; j < arr.length - 1; j++) {7 if(arr[j + 1] < arr[j])8 swap(arr, j, j + 1)9 }10 }11} */12// $ 当前这个排序有什么缺陷呢?13// $ (1)、若是在排序过程中已经是有序的了,则不需要再执行剩余的遍历次数了14// $ (2)、在每次排序过程中,可能并不只是新增一个元素是有序的15// *********针对第一种情况进行优化********16/* function bubbleSort(arr) { 17 for(let i = 0; i < arr.length; i++) {18 let isSwapped = false19 for(let j = 0; j < arr.length - 1; j++) {20 if(arr[j + 1] < arr[j]){21 swap(arr, j, j + 1)22 isSwapped = true23 }24 }25 if(!isSwapped) return // 若是存在一次遍历并没有交换元素,则表示数组已经是有序的了26 }27} */28// **********************第二种(在第一种基础之上)**********29function bubbleSort(arr) {30 let i = 031 while(i < arr.length) { // 由于不确定每次bubbleSort能保证有序的个数(最少一个),所以不能简单执行i++了事32 let lastSwappedIndex = -133 for(let j = 0; j < arr.length - 1; j++) {34 if(arr[j + 1] < arr[j]){35 swap(arr, j, j + 1)36 lastSwappedIndex = j + 1 // 最后一个交换可以保证 [j + 1, length - 1]是有序的,此时不需要对剩下数进行冒泡排序了37 }38 }39 i += arr.length - lastSwappedIndex 40 // 为什么需要执行此操作呢?41 // 因为目前可以保证[lastSwappedIndex, length - 1]有序了,42 // 所以i也应该更新到这个区间的元素个数:(length - 1) - lastSwappedIndex + 1 => length - lastSwappedIndex43 /* 44 if(!isSwapped) return45 那,为什么不需要类似上面这条语句这样的判断跳出返回了呢?或者说为什么这次优化是在第一次优化基础之上呢?46 因为:若是没有进行交换,那么lastSwappedIndex = -1, 此时length - lastSwappedIndex > length, 就不满足while的循环条件了47 */48 }49}50// 时间复杂度:O(n^2)51// 空间复杂度:O(1)52const arr = [1,1,1,3,3,4,3,2,4,2]53console.time('未经过优化的bubbleSort: ')54bubbleSort(arr)55console.timeEnd('未经过优化的bubbleSort: ')...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 console.log('Test status: ' + data.statusText);5 console.log('Test ID: ' + data.data.testId);6 console.log('Test URL: ' + data.data.summary);7 console.log('View test results: ' + data.data.userUrl);8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org');11 if (err) return console.error(err);12 console.log('Test status: ' + data.statusText);13 console.log('Test ID: ' + data.data.testId);14 console.log('Test URL: ' + data.data.summary);15 console.log('View test results: ' + data.data.userUrl);16});17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org');19 if (err) return console.error(err);20 console.log('Test status: ' + data.statusText);21 console.log('Test ID: ' + data.data.testId);22 console.log('Test URL: ' + data.data.summary);23 console.log('View test results: ' + data.data.userUrl);24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27 if (err) return console.error(err);28 console.log('Test status: ' + data.statusText);29 console.log('Test ID: ' + data.data.testId);30 console.log('Test URL: ' + data.data.summary);31 console.log('View test results: ' + data.data.userUrl);32});33var wpt = require('webpagetest');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.runTest(url, {location: 'Dulles:Chrome'}, function(err, data) {4 console.log(data);5});6{ statusCode: 400,7 data: 'Error: No test URL specified' }8 console.log(data);9});10 console.log(data);11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 lighthouseConfig: {4 "settings": {5 }6 },7}, function(err, data) {8 console.log(data);9});10var wpt = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org');12 lighthouseConfig: {13 "settings": {14 }15 },16}, function(err, data) {17 console.log(data);18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org');21 lighthouseConfig: {22 "settings": {23 }24 },25}, function(err, data) {26 console.log(data);27});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.setLang('en');3var wptools = require('wptools');4wptools.setLang('en');5var wptools = require('wptools');6wptools.setLang('en');7var wptools = require('wptools');8wptools.setLang('en');9var wptools = require('wptools');10wptools.setLang('en');11var wptools = require('wptools');12wptools.setLang('en');13var wptools = require('wptools');14wptools.setLang('en');15var wptools = require('wptools');16wptools.setLang('en');17var wptools = require('wptools');18wptools.setLang('en');19var wptools = require('wptools');20wptools.setLang('en');21var wptools = require('wptools');22wptools.setLang('en');

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2const wiki = wptools.page('Barack Obama');3wiki.get(function(err, doc) {4 console.log(doc);5});6const wptools = require('wptools');7const wiki = wptools.page('Barack Obama');8wiki.get(function(err, doc) {9 console.log(doc);10});11const wptools = require('wptools');12const wiki = wptools.page('Barack Obama');13wiki.get(function(err, doc) {14 console.log(doc);15});16const wptools = require('wptools');17const wiki = wptools.page('Barack Obama');18wiki.get(function(err, doc) {19 console.log(doc);20});21const wptools = require('wptools');22const wiki = wptools.page('Barack Obama');23wiki.get(function(err, doc) {24 console.log(doc);25});26const wptools = require('wptools');27const wiki = wptools.page('Barack Obama');28wiki.get(function(err, doc) {29 console.log(doc);30});31const wptools = require('wptools');32const wiki = wptools.page('Barack Obama');33wiki.get(function(err, doc) {34 console.log(doc);35});36const wptools = require('wptools');37const wiki = wptools.page('Barack Obama');38wiki.get(function(err, doc) {39 console.log(doc);40});41const wptools = require('wptools');42const wiki = wptools.page('Barack Obama');43wiki.get(function(err, doc) {44 console.log(doc);45});46const wptools = require('wptools');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var Wiki = wptools.page('Albert Einstein');3Wiki.get(function(err, data) {4 console.log(data);5});6var wptools = require('wptools');7var Wiki = new wptools.page('Albert Einstein');8Wiki.get(function(err, data) {9 console.log(data);10});11{ [Error: spawn ENOENT]12 '--silent' ] }

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful