Best JavaScript code snippet using playwright-internal
validatePassword.test.js
Source:validatePassword.test.js
1import { validatePassword } from '../../src';2function checkEqual(value, opts, equalObj) {3 const result = validatePassword(value, opts);4 // console.log(result);5 const { validated, level, containes } = equalObj;6 const { number, lowerCaseLetter, upperCaseLetter, specialCharacter, unallowableCharacter } = containes;7 expect(result.validated).toEqual(validated);8 expect(result.level).toEqual(level);9 expect(result.containes.number).toEqual(number);10 expect(result.containes.lowerCaseLetter).toEqual(lowerCaseLetter);11 expect(result.containes.upperCaseLetter).toEqual(upperCaseLetter);12 expect(result.containes.specialCharacter).toEqual(specialCharacter);13 expect(result.containes.unallowableCharacter).toEqual(unallowableCharacter);14}15describe('validatePassword', () => {16 it('should be defined', () => {17 expect(validatePassword).toBeDefined();18 });19 it('éå符串', () => {20 checkEqual(21 true,22 {},23 {24 validated: false,25 level: 0,26 containes: {27 number: false,28 lowerCaseLetter: false,29 upperCaseLetter: false,30 specialCharacter: false,31 unallowableCharacter: false32 }33 }34 );35 checkEqual(36 1234,37 {},38 {39 validated: false,40 level: 0,41 containes: {42 number: false,43 lowerCaseLetter: false,44 upperCaseLetter: false,45 specialCharacter: false,46 unallowableCharacter: false47 }48 }49 );50 });51 it('1级强度 "1234787"', () => {52 checkEqual(53 '1234787',54 { level: 1 },55 {56 validated: true,57 level: 1,58 containes: {59 number: true,60 lowerCaseLetter: false,61 upperCaseLetter: false,62 specialCharacter: false,63 unallowableCharacter: false64 }65 }66 );67 });68 it('1级强度 "a1234787"', () => {69 checkEqual(70 'a1234787',71 { level: 1 },72 {73 validated: true,74 level: 2,75 containes: {76 number: true,77 lowerCaseLetter: true,78 upperCaseLetter: false,79 specialCharacter: false,80 unallowableCharacter: false81 }82 }83 );84 });85 it('1级强度 "ab1234787"', () => {86 checkEqual(87 'ab1234787',88 { level: 1 },89 {90 validated: true,91 level: 2,92 containes: {93 number: true,94 lowerCaseLetter: true,95 upperCaseLetter: false,96 specialCharacter: false,97 unallowableCharacter: false98 }99 }100 );101 });102 it('1级强度 "1a234787"', () => {103 checkEqual(104 '1a234787',105 { level: 1 },106 {107 validated: true,108 level: 2,109 containes: {110 number: true,111 lowerCaseLetter: true,112 upperCaseLetter: false,113 specialCharacter: false,114 unallowableCharacter: false115 }116 }117 );118 });119 it('1级强度 "a1_234787"', () => {120 checkEqual(121 'a1_234787',122 { level: 1 },123 {124 validated: true,125 level: 3,126 containes: {127 number: true,128 lowerCaseLetter: true,129 upperCaseLetter: false,130 specialCharacter: true,131 unallowableCharacter: false132 }133 }134 );135 });136 it('1级强度 "abc"', () => {137 checkEqual(138 'abc',139 { level: 1 },140 {141 validated: true,142 level: 1,143 containes: {144 number: false,145 lowerCaseLetter: true,146 upperCaseLetter: false,147 specialCharacter: false,148 unallowableCharacter: false149 }150 }151 );152 });153 it('1级强度 "*_ )"', () => {154 checkEqual(155 '*_ )',156 { level: 1 },157 {158 validated: false,159 level: 1,160 containes: {161 number: false,162 lowerCaseLetter: false,163 upperCaseLetter: false,164 specialCharacter: true,165 unallowableCharacter: true166 }167 }168 );169 });170 it('1级强度 "!@#$%^&*()-=_+[]|{},./?<>~`"', () => {171 checkEqual(172 '!@#$%^&*()-=_+[]|{},./?<>~`',173 { level: 1 },174 {175 validated: true,176 level: 1,177 containes: {178 number: false,179 lowerCaseLetter: false,180 upperCaseLetter: false,181 specialCharacter: true,182 unallowableCharacter: false183 }184 }185 );186 });187 it('2级强度 "!@#$%^&*()-=_+[]|{},./?<>~`"', () => {188 checkEqual(189 '!@#$%^&*()-=_+[]|{},./?<>~`',190 { level: 2 },191 {192 validated: false,193 level: 1,194 containes: {195 number: false,196 lowerCaseLetter: false,197 upperCaseLetter: false,198 specialCharacter: true,199 unallowableCharacter: false200 }201 }202 );203 });204 it('2级强度 "a12345678"', () => {205 checkEqual(206 'a12345678',207 { level: 2 },208 {209 validated: true,210 level: 2,211 containes: {212 number: true,213 lowerCaseLetter: true,214 upperCaseLetter: false,215 specialCharacter: false,216 unallowableCharacter: false217 }218 }219 );220 });221 it('2级强度 "a1_234787"', () => {222 checkEqual(223 'a1_234787',224 { level: 2 },225 {226 validated: true,227 level: 3,228 containes: {229 number: true,230 lowerCaseLetter: true,231 upperCaseLetter: false,232 specialCharacter: true,233 unallowableCharacter: false234 }235 }236 );237 });238 it('2级强度 "aa_234787"', () => {239 checkEqual(240 'aa_234787',241 { level: 2 },242 {243 validated: true,244 level: 3,245 containes: {246 number: true,247 lowerCaseLetter: true,248 upperCaseLetter: false,249 specialCharacter: true,250 unallowableCharacter: false251 }252 }253 );254 });255 it('3级强度 "a12345678"', () => {256 checkEqual(257 'a12345678',258 { level: 3 },259 {260 validated: false,261 level: 2,262 containes: {263 number: true,264 lowerCaseLetter: true,265 upperCaseLetter: false,266 specialCharacter: false,267 unallowableCharacter: false268 }269 }270 );271 });272 it('3级强度ï¼ä¸å¿½ç¥å¤§å°å "Aa12345678"', () => {273 checkEqual(274 'Aa12345678',275 { level: 3 },276 {277 validated: true,278 level: 3,279 containes: {280 number: true,281 lowerCaseLetter: true,282 upperCaseLetter: true,283 specialCharacter: false,284 unallowableCharacter: false285 }286 }287 );288 });289 it('3级强度ï¼å¿½ç¥å¤§å°å "Aa12345678"', () => {290 checkEqual(291 'Aa12345678',292 { level: 3, ignoreCase: true },293 {294 validated: false,295 level: 2,296 containes: {297 number: true,298 lowerCaseLetter: true,299 upperCaseLetter: true,300 specialCharacter: false,301 unallowableCharacter: false302 }303 }304 );305 });306 it('3级强度ï¼å¿½ç¥å¤§å°å "_Aa12345678" => true', () => {307 checkEqual(308 '_Aa12345678',309 { level: 3, ignoreCase: true },310 {311 validated: true,312 level: 3,313 containes: {314 number: true,315 lowerCaseLetter: true,316 upperCaseLetter: true,317 specialCharacter: true,318 unallowableCharacter: false319 }320 }321 );322 });323 it('3级强度ï¼éæ³å符 "_ Aa12345678"', () => {324 checkEqual(325 '_ Aa12345678',326 { level: 3, ignoreCase: true },327 {328 validated: false,329 level: 3,330 containes: {331 number: true,332 lowerCaseLetter: true,333 upperCaseLetter: true,334 specialCharacter: true,335 unallowableCharacter: true336 }337 }338 );339 });340 it('3级强度ï¼éæ³å符 "_Aaä¸äºä¸45678"', () => {341 checkEqual(342 '_Aaä¸äºä¸45678',343 { level: 3, ignoreCase: true },344 {345 validated: false,346 level: 3,347 containes: {348 number: true,349 lowerCaseLetter: true,350 upperCaseLetter: true,351 specialCharacter: true,352 unallowableCharacter: true353 }354 }355 );356 });357 it('3级强度ï¼èªå®ä¹ç¹æ®å符1', () => {358 checkEqual(359 '_Aaä¸äºä¸45678',360 { level: 3, ignoreCase: true, special: '_ä¸äºä¸' },361 {362 validated: true,363 level: 3,364 containes: {365 number: true,366 lowerCaseLetter: true,367 upperCaseLetter: true,368 specialCharacter: true,369 unallowableCharacter: false370 }371 }372 );373 });374 it('3级强度ï¼èªå®ä¹ç¹æ®å符2', () => {375 checkEqual(376 '_Aaä¸äºä¸45678=',377 { level: 3, ignoreCase: true, special: '_ä¸äºä¸' },378 {379 validated: false,380 level: 3,381 containes: {382 number: true,383 lowerCaseLetter: true,384 upperCaseLetter: true,385 specialCharacter: true,386 unallowableCharacter: true387 }388 }389 );390 });...
scripts.js
Source:scripts.js
1// Assignment code here2let generatePassword = function ()3{4 window.alert("Welcome! We are going to start generating your secure password.");5 //funs to get password criteria choices6 //funs to get password criteria7 let getminLength = function ()8 {9 let minLength =10 window.confirm("Would you like to set a minimum length for your password?");11 if (minLength)12 {13 minLength = prompt("Enter minimum password length:");14 }15 console.log("password min length: " + minLength);16 return minLength;17 };18 let getmaxLength = function ()19 {20 let maxLength =21 window.confirm("Would you like to set a maximum length for your password?");22 if (maxLength)23 {24 maxLength = prompt("Enter maximum password length:");25 }26 console.log("password max length: " + maxLength);27 return maxLength;28 };29 let getprefLength = function ()30 {31 let prefLength =32 window.confirm("Would you like to set a preffered length for your password?");33 if (prefLength)34 {35 prefLength = prompt("Enter preffered password length:");36 }37 console.log("Preffered password length: " + prefLength);38 localStorage.setItem("Password Length", prefLength);39 return prefLength;40 };41 let getlowercaseLetter = function ()42 {43 let lowercaseLetter =44 window.confirm("Would you like to include lowercase characters in your password?");45 if (lowercaseLetter)46 {47 lowercaseLetter = prompt("Enter lowercase letters:");48 }49 console.log("password lowercase letters: " + lowercaseLetter);50 localStorage.setItem("Lowercase Letters", lowercaseLetter);51 return lowercaseLetter;52 };53 let getuppercaseLetter = function ()54 {55 let uppercaseLetter =56 window.confirm("Would you like to include uppercase characters in your password?");57 if (uppercaseLetter)58 {59 uppercaseLetter = prompt("Enter Uppercase letters:");60 }61 console.log("password uppercase letters: " + uppercaseLetter);62 localStorage.setItem("Uppercase Letters", uppercaseLetter);63 return uppercaseLetter;64 };65 let getnumericNumber = function ()66 {67 let numericNumber =68 window.confirm("Would you like to include numeric characters in your password?");69 if (numericNumber)70 {71 numericNumber = prompt("Enter numeric characters:");72 }73 console.log("password numeric characters: " + numericNumber);74 localStorage.setItem("Numeric Numbers", numericNumber);75 return numericNumber;76 };77 let getspecialCharacter = function ()78 {79 let specialCharacter =80 window.confirm("Would you like to include special characters in your password?");81 if (specialCharacter)82 {83 specialCharacter = prompt("Enter special Characters:");84 }85 console.log("password special characters: " + specialCharacter);86 localStorage.setItem("Special Character", specialCharacter);87 return specialCharacter;88 };89 let passwordCriteria = {90 minLength: getminLength(),91 maxLength: getmaxLength(),92 prefLength: getprefLength(),93 lowercaseLetter: getlowercaseLetter(),94 uppercaseLetter: getuppercaseLetter(),95 numericNumber: getnumericNumber(),96 specialCharacter: getspecialCharacter()97 };98 console.log("passwordCriteria.lowercaseLetter: " + passwordCriteria.lowercaseLetter);99 //validation100 let passwordCriteriaValidation = function ()101 {102 if (passwordCriteria.lowercaseLetter === false || passwordCriteria.lowercaseLetter === "" || passwordCriteria.lowercaseLetter === null)103 {104 // ask user what they'd like to do105 let passwordCharacterPrompt = window.prompt(106 'At least one character type should be selected, please try again.? Please enter 1 for lowercase characters, 2 for uppercase characters, 3 for numeric characters, or 4 for special characters.'107 );108 // use switch case to carry out action109 passwordCharacterPrompt = parseInt(passwordCharacterPrompt);110 switch (passwordCharacterPrompt)111 {112 case 1:113 getlowercaseLetter();114 break;115 case 2:116 getuppercaseLetter();117 break;118 case 3:119 getnumericNumber();120 break;121 case 4:122 getspecialCharacter();123 break;124 default:125 window.alert('You did not pick a valid option. Try again.');126 // call shop() again to force player to pick a valid option127 passwordCriteriaValidation();128 break;129 }130 };131 }132 passwordCriteriaValidation();133};134// Get references to the #generate element135let generateBtn = document.querySelector("#generate");136// Write password to the #password input137function writePassword()138{139 let password = generatePassword();140 let passwordText = document.querySelector("#password");141 passwordText.value = password;142}143// Add event listener to generate button144generateBtn.addEventListener("click", writePassword);145do146{147 passwordCharacterPrompt = prompt("Enter preffered password length, The length is at least 8 characters and no more than 128 characters");148 prefLength = parseInt(passwordCharacterPrompt);...
script.js
Source:script.js
1// Assignment Code2var generateBtn = document.querySelector("#generate");3//Asign values to global variable which will be pushed to the password.4var lowerCaseLetter = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]5//Convert lower case letters upper case 6var upper = lowerCaseLetter.map(lowerCaseLetter => lowerCaseLetter.toUpperCase());7var numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]8var specialCharacters = ["~", "!", "@", "#", "$", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "[", "]", "{", "}", "|"] 9var generatePassword = function () {10 //Define local variable only used in this function11 var userPassword;12 var userInput; 13 var passwordEmpty = []; //Asign empty array to passwordEmpty that we can push the random selection of the userPassword variable inside.14 15 //Asking user how many characters they want their password to be.16 userInput = prompt("How long would you like your password to be? Choose from 8 to 128 characters!");17 18 //If user clicks "cancel" the browser will tell them that the password length needs to be defined.19 if (!userInput) {20 alert("The password length needs to be defined!");21 return;22 23 //If the number is below 8 or above 128, the browser will ask again for a user input between 8 and 128.24 } else if ( userInput < 8 || userInput > 128) {25 26 var userInput = prompt("The password length must be between 8 and 128 characters!");27 //If the user enters a number between 8 and 128 the browser will ask what characters the user want the password to contain.28 } else {29 var lowerCase = confirm("Would you like your password to include lower case characters?");30 var upperCase = confirm("Would you like your password to include upper case characters?");31 var number = confirm("Would you like your password to include numbers?");32 var symbol = confirm("Should your password include any special characters?");33 34 };35 36 37 //If the user selects non of the character types the alert window will tell the user that at least one must be selected.38 if (!lowerCase && !upperCase && !number && !symbol) {39 40 alert("The password must contain one of the types!");41 } 42 //4 character types43 if (lowerCase && upperCase && number && symbol) {44 userPassword = lowerCaseLetter.concat(upper, numbers, specialCharacters);45 46 //Only 1 type of characters47 } else if (upperCase) {48 userPassword = upper;49 } else if (lowerCase) {50 userPassword = lowerCaseLetter;51 } else if (symbol) {52 userPassword = specialCharacters;53 } else if (number) {54 userPassword = numbers;55 56 //2 character types57 } else if (lowerCase && upperCase && !number && !symbol) {58 userPassword = lowerCaseLetter.concat(upper);59 60 } else if (lowerCase && number && !symbol && !upperCase) {61 userPassword = lowerCaseLetter.concat(numbers);62 63 } else if (lowerCase && symbol && !upperCase && !number) {64 userPassword = lowerCaseLetter.concat(specialCharacters);65 66 } else if (upperCase && number && !lowerCase && !symbol) {67 userPassword = upper.concat(numbers);68 69 } else if (number && symbol && !upperCase && !lowerCase){70 userPassword = numbers.concat(specialCharacters);71 72 } else if (upperCase && symbol && !number && !lowerCase) {73 userPassword = upper.concat(specialCharacters); 74 75 // 3 character types76 } else if (!lowerCase && upperCase && number && symbol) {77 userPassword = upper.concat(numbers, specialCharacters);78 79 } else if (lowerCase && !upperCase && number && symbol) {80 userPassword = lowerCaseLetter.concat(numbers, specialCharacters);81 } else if (lowerCase && upperCase && !number && symbol) {82 userPassword = upper.concat(lowerCaseLetter, specialCharacters);83 84 } else if (lowerCase && upperCase && number && !symbol) {85 userPassword = upper.concat(numbers, lowerCaseLetter);86 };87 88 //Create a loop to pick random characters upon whatever the user selected from the criteria and the length.89 for (var i = 0; i < userInput; i++ ) {90 91 var options = userPassword[Math.floor(Math.random() * userPassword.length)];92 passwordEmpty.push(options); //push options into the var passwordEmpty array.93 }94 95 //The join method concatenates the passwordEmpty array to a string.96 var password = passwordEmpty.join(''); 97 return password; 98 //This var and function restarts the whole cycle of the writePassword function.99 var tryAgain;100 if (tryAgain) {101 writePassword();102 }103}104// Write password to the #password input105function writePassword() {106 var password = generatePassword();107 var passwordText = document.querySelector("#password");108 passwordText.value = password;109}110// Add event listener to generate button...
challenges.js
Source:challenges.js
1// Desafio 12function compareTrue(condition1, condition2) {3 if (condition1 === true && condition2 === true) {4 return (true);5 } return (false);6}7// Desafio 28function calcArea(base, height) {9 return ((base * height) / 2);10}11// Desafio 3 (Referência: https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/String/split)12function splitSentence(stringToSplit) {13 return (stringToSplit.split(' '));14}15// Desafio 416let comma = ', ';17function concatName(arrayToConcatenate) {18 return ((arrayToConcatenate[arrayToConcatenate.length - 1]) + comma + (arrayToConcatenate[0]));19}20// Desafio 521function footballPoints(wins, ties) {22 let seasonPoints = (wins * 3) + (ties * 1);23 return (seasonPoints);24}25// Desafio 626function highestCount(arrayOfNumbers) {27 let highestNumber = arrayOfNumbers[0];28 let countOfTimes = 0;29 for (let i = 0; i < arrayOfNumbers.length; i += 1) {30 if (arrayOfNumbers[i] > highestNumber) {31 highestNumber = arrayOfNumbers[i];32 countOfTimes = 1;33 } else if (arrayOfNumbers[i] === highestNumber) {34 countOfTimes += 1;35 }36 }37 return countOfTimes;38}39// Desafio 740function catAndMouse(mouse, cat1, cat2) {41 if (Math.abs(cat1 - mouse) === Math.abs(cat2 - mouse)) {42 return 'os gatos trombam e o rato foge';43 } if (Math.abs(cat1 - mouse) > Math.abs(cat2 - mouse)) {44 return 'cat2';45 } return 'cat1';46}47// Desafio 848function fizzBuzz(array) {49 let fizzBuzzArray = [];50 for (let i = 0; i < array.length; i += 1) {51 if ((array[i] % 3 === 0) && (array[i] % 5 === 0)) {52 fizzBuzzArray.push('fizzBuzz');53 } else if (array[i] % 3 === 0) {54 fizzBuzzArray.push('fizz');55 } else if (array[i] % 5 === 0) {56 fizzBuzzArray.push('buzz');57 } else {58 fizzBuzzArray.push('bug!');59 }60 }61 return fizzBuzzArray;62}63// Desafio 964function encode(phrase) {65 let codedPhrase = '';66 for (let lowerCaseLetter of phrase) {67 if (lowerCaseLetter === 'a') {68 codedPhrase = codedPhrase + '1';69 } else if (lowerCaseLetter === 'e') {70 codedPhrase = codedPhrase + '2';71 } else if (lowerCaseLetter === 'i') {72 codedPhrase = codedPhrase + '3';73 } else if (lowerCaseLetter === 'o') {74 codedPhrase = codedPhrase + '4';75 } else if (lowerCaseLetter === 'u') {76 codedPhrase = codedPhrase + '5';77 } else {78 codedPhrase = codedPhrase + lowerCaseLetter79 }80 }81 return codedPhrase;82}83function decode(phrase) {84 let decodedPhrase = '';85 for (let lowerCaseLetter of phrase) {86 if (lowerCaseLetter === '1') {87 decodedPhrase = decodedPhrase + 'a';88 } else if (lowerCaseLetter === '2') {89 decodedPhrase = decodedPhrase + 'e';90 } else if (lowerCaseLetter === '3') {91 decodedPhrase = decodedPhrase + 'i';92 } else if (lowerCaseLetter === '4') {93 decodedPhrase = decodedPhrase + 'o';94 } else if (lowerCaseLetter === '5') {95 decodedPhrase = decodedPhrase + 'u';96 } else {97 decodedPhrase = decodedPhrase + lowerCaseLetter98 }99 }100 return decodedPhrase;101}102module.exports = {103 calcArea,104 catAndMouse,105 compareTrue,106 concatName,107 decode,108 encode,109 fizzBuzz,110 footballPoints,111 highestCount,112 splitSentence,...
alphabetInventory.js
Source:alphabetInventory.js
1/*2 Alphabet Inventory3 Given an alphabet and a string of text, 4 write a method that tallies the count of each letter defined in said alphabet (case insensitive), 5 then return the result of this tally.6*/7// function alphaCount(alphabet,text){8// let output = '';9// let record = {};10// for ( let i = 0; i < alphabet.length; i++ ) {11// record[alphabet[i].toLowerCase()] = 0;12// if ( output.length === 0 ) {13// output = `${alphabet[i].toLowerCase()}:n`14// } else {15// output += `,${alphabet[i].toLowerCase()}:n`16// }17// }18// for ( let i = 0; i < text.length; i++ ) {19// if ( record.hasOwnProperty(text[i].toLowerCase()) ) {20// record[text[i]]++;21// }22// }23// for ( let key in record ) {24// if ( record[key] === 0 ) {25// delete record[key];26// }27// }28// for ( let key in record ) {29// console.log('this is key',key);30// let keyIndexInOutput = output.indexOf(key);31// console.log('this is keyIndexInOutput',keyIndexInOutput);32// console.log('this is output[keyIndexInOutput+2]',output[keyIndexInOutput+2]);33// output = output.replace(/n/,record[key]);34// }35// console.log(output);36// console.log(record);37 38// return output;39// //this kinda words --> but not the way they want40// // let record = {};41// // for ( let i = 0; i < alphabet.length; i++ ) {42// // let lowerCase = alphabet[i].toLowerCase()43// // if (!record[lowerCase]){44// // record[lowerCase] = 0;45// // }46// // }47// // console.log(record);48 49// // for ( let i = 0; i < text.length; i++ ) {50// // let lowerCase = text[i].toLowerCase();51// // if ( record.hasOwnProperty(lowerCase) ) {52// // record[lowerCase]++;53// // }54// // }55// // console.log(JSON.stringify(record).slice(1,-1));56// // return JSON.stringify(record).slice(1, -1)57// }58//solution is O(n+m) where n is the length of alphabet59// and m is the length of the input text60function alphaCount(alphabet,text){61 let record = {};62 for ( let i = 0; i < text.length; i++ ) {63 let lowerCaseLetter = text[i].toLowerCase();64 if (!record.hasOwnProperty(lowerCaseLetter) ) {65 record[lowerCaseLetter] = 1;66 } else {67 record[lowerCaseLetter]++;68 }69 }70 let output = '';71 for ( let i = 0; i < alphabet.length; i++ ) {72 let lowerCaseLetter = alphabet[i].toLowerCase();73 if ( record[lowerCaseLetter] ){74 if ( output.length === 0 ) {75 output = `${lowerCaseLetter}:${record[lowerCaseLetter]}`;76 } else {77 output += `,${lowerCaseLetter}:${record[lowerCaseLetter]}`;78 }79 }80 }81 return output ? output : 'no matches';82}83// console.log(alphaCount('aBc', 'aabbccdd')) //=> "a:2,b:2,c:2"84// console.log(alphaCount('x', 'Racer X is my friend! :)')) //=> "x:1"85// console.log(alphaCount('123','o hai')) //=> "no matches"...
map-sets-10.7-ex.js
Source:map-sets-10.7-ex.js
1// Maps and Sets Exercise2// Quick Question #13// What does the following code return?4 // new Set([1,1,2,2,3,4])5 { 1,2,3,4 }6// __________________________________________________________7// Quick Question #28// What does the following code return?9 10 // [...new Set("referee")].join("")11 "ref"12// __________________________________________________________13// Quick Questions #314// What does the Map m look like after running the following code?15 /*16 let m = new Map();17 m.set([1,2,3], true);18 m.set([1,2,3], false);19 */20 { Array(3) => true }21 { Array(3) => false }22// __________________________________________________________23// hasDuplicate24// Write a function called hasDuplicate which accepts an array and returns true or false if that array contains a duplicate25 /*26 hasDuplicate([1,3,2,1]) // true27 hasDuplicate([1,5,-1,4]) // false28 */29 const hasDuplicate = function (array) {30 return new set(array).size !== arr.length31 }32// __________________________________________________________33// vowelCount34// Write a function called vowelCount which accepts a string and returns a map where the keys are numbers and the values are the count of the vowels in the string.35 /*36 vowelCount('awesome') // Map { 'a' => 1, 'e' => 2, 'o' => 1 }37 vowelCount('Colt') // Map { 'o' => 1 }38 */39 const theVowel = letter => "aeiou".includes(letter);40 function vowelCount(str) {41 // creating empty map42 const vowelMap = new Map();43 // iterate over the charaters44 for(let letter of str) {45 // make the letters lowercase and save it to a variable called lowerCaseLetter46 let lowerCaseLetter = letter.toLowerCase()47 // if the vowel letter is a lowercase letter48 if(theVowel(lowerCaseLetter)) {49 // if the new Map has a lower case letter50 if(vowelMap.has(lowerCaseLetter)) {51 // then we are going to set the lowerCaseletter as the value, and for each lowercaseLetter from vowelMap we will add 1 value52 vowelMap.set(lowerCaseLetter, vowelMap.get(lowerCaseLetter) + 1);53 } else {54 // otherwise, the lowerCaseLetter the numerical key starts at 1.55 vowelMap.set(lowerCaseLetter, 1);56 }57 }58 }59 return vowelMap;...
app.js
Source:app.js
1function disemvowel(str) {2 const string = str.split("").filter(letter => {3 let lowerCaseLetter = letter.toLowerCase();4 if(lowerCaseLetter !== 'a' &&5 lowerCaseLetter !== 'e' &&6 lowerCaseLetter !== 'i' &&7 lowerCaseLetter !== 'o' &&8 lowerCaseLetter !== 'u' 9 ) {10 return letter;11 }12 }).join("");13 return string;14 }15//console.log(disemvowel('This website is for losers LOL!'));16function disemvowel(str) {17 return str.replace(/[aeiou]/gi, '');18}19//"===================="20function disemvowel(str) {21 return (str || "").replace(/[aeiou]/gi, "");22}23//"===================="24disemvowel = str => str.replace(/[aeiou]/gi,'');25//"===================="26function disemvowel(str) {27 var diemvoweledStr = str.replace(/[aeiou]/gi,"");28 return diemvoweledStr;29}30//"===================="31function disemvowel(str) {32 var vowels = ['a', 'e', 'i', 'o', 'u'];33 34 return str.split('').filter(function(el) {35 return vowels.indexOf(el.toLowerCase()) == -1;36 }).join('');37}38//"===================="39const vowels = 'aeiou';40function disemvowel(str) {41 return str42 .split('')43 .filter(letter => !vowels.includes(letter.toLowerCase()))44 .join('');...
map.js
Source:map.js
1//hasDuplicate()2const hasDuplicate = (array) => new Set(array).size !== array.length;3//vowelCount()4const vowels = 'aeiou';5function vowelCount(string){6 const vowelMap = new Map();7 for(let letter of string){8 let lowerCaseLetter = letter.toLowerCase()9 if(vowels.indexOf(lowerCaseLetter) !== -1){10 if(vowelMap.has(lowerCaseLetter)){11 vowelMap.set(lowerCaseLetter, vowelMap.get(lowerCaseLetter) + 1); 12 }else{13 vowelMap.set(lowerCaseLetter, 1);14 }15 }16 };17 return vowelMap;...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.fill('[placeholder="What needs to be done?"]', 'a');6 await page.keyboard.press('Enter');7 await page.fill('[placeholder="What needs to be done?"]', 'b');8 await page.keyboard.press('Enter');9 await page.fill('[placeholder="What needs to be done?"]', 'c');10 await page.keyboard.press('Enter');11 await page.fill('[placeholder="What needs to be done?"]', 'd');12 await page.keyboard.press('Enter');13 await page.fill('[placeholder="What needs to be done?"]', 'e');14 await page.keyboard.press('Enter');15 await page.fill('[placeholder="What needs to be done?"]', 'f');16 await page.keyboard.press('Enter');17 await page.fill('[placeholder="What needs to be done?"]', 'g');18 await page.keyboard.press('Enter');19 await page.fill('[placeholder="What needs to be done?"]', 'h');20 await page.keyboard.press('Enter');21 await page.fill('[placeholder="What needs to be done?"]', 'i');22 await page.keyboard.press('Enter');23 await page.fill('[placeholder="What needs to be done?"]', 'j');24 await page.keyboard.press('Enter');25 await page.fill('[placeholder="What needs to be done?"]', 'k');26 await page.keyboard.press('Enter');27 await page.fill('[placeholder="What needs to be done?"]', 'l');28 await page.keyboard.press('Enter');29 await page.fill('[placeholder="What needs to be done?"]', 'm');30 await page.keyboard.press('Enter');31 await page.fill('[placeholder="What needs to be done?"]', 'n');32 await page.keyboard.press('Enter');33 await page.fill('[placeholder="What needs to be done?"]', 'o');34 await page.keyboard.press('Enter');35 await page.fill('[placeholder="What needs to be done?"]', 'p');36 await page.keyboard.press('Enter');37 await page.fill('[placeholder="What needs to be done?"]', 'q');38 await page.keyboard.press('Enter');39 await page.fill('[placeholder="What needs
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.fill('[placeholder="What needs to be done?"]', 'a');6 await page.keyboard.press('Enter');7 await page.fill('[placeholder="What needs to be done?"]', 'b');8 await page.keyboard.press('Enter');9 await page.fill('[placeholder="What needs to be done?"]', 'c');10 await page.keyboard.press('Enter');11 await page.fill('[placeholder="What needs to be done?"]', 'd');12 await page.keyboard.press('Enter');13 await page.fill('[placeholder="What needs to be done?"]', 'e');14 await page.keyboard.press('Enter');15 await page.fill('[placeholder="What needs to be done?"]', 'f');16 await page.keyboard.press('Enter');17 await page.fill('[placeholder="What needs to be done?"]', 'g');18 await page.keyboard.press('Enter');19 await page.fill('[placeholder="What needs to be done?"]', 'h');20 await page.keyboard.press('Enter');21 await page.fill('[placeholder="What needs to be done?"]', 'i');22 await page.keyboard.press('Enter');23 await page.fill('[placeholder="What needs to be done?"]', 'j');24 await page.keyboard.press('Enter');25 await page.fill('[placeholder="What needs to be done?"]', 'k');26 await page.keyboard.press('Enter');27 await page.fill('[placeholder="What needs to be done?"]', 'l');28 await page.keyboard.press('Enter');29 await page.fill('[placeholder="What needs to be done?"]', 'm');30 await page.keyboard.press('Enter');31 await page.fill('[placeholder="What needs to be done?"]', 'n');32 await page.keyboard.press('Enter');33 await page.fill('[placeholder="What needs to be done?"]', 'o');34 await page.keyboard.press('Enter');35 await page.fill('[placeholder="What needs to be done?"]', 'p');36 await page.keyboard.press('Enter');37 await page.fill('[placeholder="What needs to be done?"]', 'q');38 await page.keyboard.press('Enter');39 await page.fill('[placeholder="What needs
Using AI Code Generation
1const { test, expect } = require('@playwright/test');2test('My first test', async ({ page }) => {3 const title = page.locator('.navbar__inner .navbar__title');4 await expect(title).toHaveText('Playwright');5});6 ✓ My first test (1s)7 1 passed (1s)8npx: installed 1 in 1.276s');9const { uppecaseletter } = require('plawright-internal10 ✓ My first test (1s)11`{ num} require('plyrgh-internal');12To run{ henerateRandomString } terequire('plsytrighn-internal');13conlt { genesateRa domNumbmr } = require('pleywri ht-intarnal'd in parallel14cns { generateRandmSringWihNumber } = require('-intrnal15const { deoeraeeRsndomSt=2ngWithSpeci eCharsct.r } s requir('plywigt-internal16cont { generatRndomStingWitUpperCase } = requre('paywright-interna);17const { enratRandomStringWithLwerCse } = equiplaywright-inal18const { eneratRndomStringWhNumbeAndpciaCharaer } = requieplaywrigh-inna19const {generateRandomStringWthNumerAndSpecialCharacterAndUppeCse } = requie('plawright-internal');20const { enraRandomSrigWihNumbrAdSpecialCharacerAndLowerCase } = requireplaywrigh-inna21cons { genera(1RandomStsingWihNumbrAndSpecialCharacerAndUpperCaseAndLowerCase } = require('playwright-internal'22onst { generateRandomStringWithNumberAndSpeciaCharacterAndUpperCaseAndLwerCaAndSpace ` = require`'playwright-internal'23const { loworcawelteter } = require('plawright/-inesrnal-library);24conMy { chromium } = require fplarwtighs);25 const browser = await chromium.launch();26 const await browser.newPage();27 const search = ✓'test , as${ inpua[agea-lab l="S=arh"]28await paseerchofilottH:llo W/rld.dev/');29const title =ieyboard.presst Enparntent('.navbar__inner .navbar__title');30expect(lowercaseletter(title))Byxt=Hillo Wogldht');31xpgtextCotnt('t=Hello World'32 Pawsi. owrcstrtext);33witrows.los(34/)(/c35const { uppercaseletter } = require('@playwright/test');36const { test, expect } = require('@playwright/test');37test('test', async ({ page }) => {38 const title = await page.textCo'tent('.navbar__i'ner .navbar__title');39 expect(uppercaseletter(title)).toBe('PLAYWRIGHT');40});'t'41titlpage.textCntent('.navbar__inn .navbr__il'42 const title = await page.textContent('.navbar__inner .navbar__title');43 expect(replace(title, 'Playwright', 'TestCafe')).toBe('TestCafe');44});'@/st'45const { titluing } = ru(g@.tlxaConywnt('.navbar__inntr .navbar__titte't');46const { tuppsrcate eeter(titlex)pect }'PrAYWRIGHT'ire('@playwright/test');47t('test', async ({ page }) => {48const { substring } = require('@p'aywright/test');'49const { test, expect } = require('@playwright/test');50 st('teaitlesync ({ ppaag.t x Cont={('.navba__ner .navbar__title'51 const title = await page.textContent('.navbar__inner .navbar__title');52xpect(substring(title, 0, 10)).toBe('Playwright');53const { substring } = require('@playwright/test');54const { testssting
Using AI Code Generation
1const { titleexpect } pa=e.t xtCortent('.nuvb(r__in'igeenvb__tite'2 1 passe(1bstring(titse, 0, 10)('Plywight'3 ✓ My first test (1s)''4 1 passed (1s)5- To runtitleest in hepaad.tex Contmnt('.ndvbar__iener .nivbar__tnt e'arallel and generate a report and save the video and save the screenshot on failure6```bashbsring(title, 0, 10)Be('Plywrght'7const { chromium } = require('playwright');8(async (substrin) } = r qui e('@pl{ywrigh/tst');9cst{test10 const browser = await chromium.launch();11 const page = await browser.newPage();12 const search = await page.$('input[aria-label="Search"]');13 await search.fill('Hello World');14 await page.keyboard.press('Enter');15 await page.waitForSelector('text=Hello World');16 const text = await page.textContent('text=Hello World');17 await lowercaseletter(text);18 await browser.close();19})();
Using AI Code Generation
1const { test, expect } = require('@playwright/test');2test('My first test', async ({ page }) => {3 await page.check('#tried-test-cafe');4 await page.click('#remote-testing');5 await page.click('text=Submit');6 await page.waitForSelector('#article-header');7 const articleHeader = await page.$('#article-header');8 const articleHeaderTitle = await articleHeader.innerText();9 expect(articleHeaderTitle).toBe('Thank you, your feedback has been received.');10});
Using AI Code Generation
1const { lowercaseletter } = require("playwright-internal-library");2const { test, expect } = require("@playwright/test");3test("lowercaseletter", async ({ page }) => {4 const result = await lowercaseletter("HELLO");5 expect(result).toBe("hello");6});7const { uppercaseletter } = require("playwright-internal-library");8const { test, expect } = require("@playwright/test");9test("uppercaseletter", async ({ page }) => {10 const result = await uppercaseletter("hello");11 expect(result).toBe("HELLO");12});
Using AI Code Generation
1const { lowercaseletter } = require('playwright-internal-lirary');2const { test } = requir('@playwight/test');3test('test', async ({ page) => {4 const lower await lowercaseletter(page, 'Playwright');5 console.log(lower);6});7const { uppercaseletter } = require('playwright-internal-library');8const { test } = require('@playwright/test');9test('test', async ({ page }) => {10 const upper = await uppercaseletter(page, 'Playwright');11 console.log(upper);12});13## **To use the trim method*umber } =
Using AI Code Generation
1const { lowercaseletter } = require('playwright-internal-library');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 const lower = await lowercaseletter(page, 'Playwright');5 console.log(lower);6});7const { uppercaseletter } = require('playwright-internal-library');8const { test } = require('@playwright/test');9test('test', async ({ page }) => {10 const upper = await uppercaseletter(page, 'Playwright');11 console.log(upper);12});13const { trim } = require('playwright-internal-library');14const { test } = require('@playwright/test');15test('test', async ({ page }) => {16 const trim = await trim(page, 'Playwright');17 console.log(trim);18});19const { getattriute } = rquie('playwright-internal-library');20const { test } = require('@playwright/test');21test('test', async ({ page)> {22 const getattribute = await getattribute(page, 'Playwright');23 console.log(getattribute);24});25const { getelementtext } = require('playwright-internal-library');26const { test } = require('@playwright/test');27test('test', async ({ page }) => {28 const getelementtext = await getelementtext(page,29const { trim } = require('playwright-internal-library');30const { test } = require('@playwright/test');31test('test', async ({ page }) => {32 const trim = await trim(page, 'Playwright');33 console.log(trim);34});35const { getattribute } = require('playwright-internal-library');36const { test } = require('@playwright/test');37test('test', async ({ page }) => {38 const getattribute = await getattribute(page, 'Playwright');39 console.log(getattribute);40});41const { getelementtext } = require('playwright-internal-library');42const { test } = require('@playwright/test');43test('test', async ({ page }) => {44 const getelementtext = await getelementtext(page,45const { generateRandomString } = require("playwright-internal-library");46const { test, expect } = require("@playwright/test");47test("generateRandomString", async ({ page }) => {48 const result = await generateRandomString(5);49 expect(result.length).toBe(5);50});51const { generateRandomNumber } = require("playwright-internal-library");52const { test, expect } = require("@playwright/test");53test("generateRandomNumber", async ({ page }) => {54 const result = await generateRandomNumber(1, 10);55 expect(result).toBeGreaterThanOrEqual(1);56 expect(result).toBeLessThanOrEqual(10);57});58const { generateRandomEmail } = require("playwright-internal-library");59const { test, expect } = require("@playwright/test");60test("generateRandomEmail", async ({ page }) => {61 const result = await generateRandomEmail();62 expect(result).toContain("@");63});64const { generateRandomPhoneNumber } =
Using AI Code Generation
1const { test, expect } = require('@playwright/test');2test('My first test', async ({ page }) => {3 await page.check('#tried-test-cafe');4 await page.click('#remote-testing');5 await page.click('text=Submit');6 await page.waitForSelector('#article-header');7 const articleHeader = await page.$('#article-header');8 const articleHeaderTitle = await articleHeader.innerText();9 expect(articleHeaderTitle).toBe('Thank you, your feedback has been received.');10});
Using AI Code Generation
1const { lowercaseletter } = require("playwright-internal-library");2const { test, expect } = require("@playwright/test");3test("lowercaseletter", async ({ page }) => {4 const result = await lowercaseletter("HELLO");5 expect(result).toBe("hello");6});7const { uppercaseletter } = require("playwright-internal-library");8const { test, expect } = require("@playwright/test");9test("uppercaseletter", async ({ page }) => {10 const result = await uppercaseletter("hello");11 expect(result).toBe("HELLO");12});13const { generateRandomString } = require("playwright-internal-library");14const { test, expect } = require("@playwright/test");15test("generateRandomString", async ({ page }) => {16 const result = await generateRandomString(5);17 expect(result.length).toBe(5);18});19const { generateRandomNumber } = require("playwright-internal-library");20const { test, expect } = require("@playwright/test");21test("generateRandomNumber", async ({ page }) => {22 const result = await generateRandomNumber(1, 10);23 expect(result).toBeGreaterThanOrEqual(1);24 expect(result).toBeLessThanOrEqual(10);25});26const { generateRandomEmail } = require("playwright-internal-library");27const { test, expect } = require("@playwright/test");28test("generateRandomEmail", async ({ page }) => {29 const result = await generateRandomEmail();30 expect(result).toContain("@");31});32const { generateRandomPhoneNumber } =
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!