Best JavaScript code snippet using wpt
jquery.expander.js
Source:jquery.expander.js
1/*2 * jQuery Expander plugin3 * Version 0.4 (12/09/2008)4 * @requires jQuery v1.1.1+5 *6 * Dual licensed under the MIT and GPL licenses:7 * http://www.opensource.org/licenses/mit-license.php8 * http://www.gnu.org/licenses/gpl.html9 *10 */11(function($) {12 $.fn.expander = function(options) {13 var opts = $.extend({}, $.fn.expander.defaults, options);14 var delayedCollapse;15 return this.each(function() {16 var $this = $(this);17 var o = $.meta ? $.extend({}, opts, $this.data()) : opts;18 var cleanedTag, startTags, endTags; 19 var allText = $this.html();20 var startText = allText.slice(0, o.slicePoint).replace(/\w+$/,'');21 startTags = startText.match(/<\w[^>]*>/g);22 if (startTags) {startText = allText.slice(0,o.slicePoint + startTags.join('').length).replace(/\w+$/,'');}23 24 if (startText.lastIndexOf('<') > startText.lastIndexOf('>') ) {25 startText = startText.slice(0,startText.lastIndexOf('<'));26 }27 var endText = allText.slice(startText.length); 28 // create necessary expand/collapse elements if they don't already exist29 if (!$('span.details', this).length) {30 // end script if text length isn't long enough.31 if ( endText.replace(/\s+$/,'').split(' ').length < o.widow ) { return; }32 // otherwise, continue... 33 if (endText.indexOf('</') > -1) {34 endTags = endText.match(/<(\/)?[^>]*>/g);35 for (var i=0; i < endTags.length; i++) {36 if (endTags[i].indexOf('</') > -1) {37 var startTag, startTagExists = false;38 for (var j=0; j < i; j++) {39 startTag = endTags[j].slice(0, endTags[j].indexOf(' ')).replace(/(\w)$/,'$1>');40 if (startTag == rSlash(endTags[i])) {41 startTagExists = true;42 }43 } 44 if (!startTagExists) {45 startText = startText + endTags[i];46 var matched = false;47 for (var s=startTags.length - 1; s >= 0; s--) {48 if (startTags[s].slice(0, startTags[s].indexOf(' ')).replace(/(\w)$/,'$1>') == rSlash(endTags[i]) 49 && matched == false) {50 cleanedTag = cleanedTag ? startTags[s] + cleanedTag : startTags[s];51 matched = true;52 }53 };54 }55 }56 }57 endText = cleanedTag && cleanedTag + endText || endText;58 }59 $this.html([60 startText,61 '<span class="read-more">',62 o.expandPrefix,63 '<a href="#">',64 o.expandText,65 '</a>',66 '</span>',67 '<span class="details">',68 endText,69 '</span>'70 ].join('')71 );72 }73 var $thisDetails = $('span.details', this),74 $readMore = $('span.read-more', this);75 $thisDetails.hide();76 $readMore.find('a').click(function() {77 $readMore.hide();78 if (o.expandEffect === 'show' && !o.expandSpeed) {79 o.beforeExpand($this);80 $thisDetails.show();81 o.afterExpand($this);82 delayCollapse(o, $thisDetails);83 } else {84 o.beforeExpand($this);85 $thisDetails[o.expandEffect](o.expandSpeed, function() {86 $thisDetails.css({zoom: ''});87 o.afterExpand($this);88 delayCollapse(o, $thisDetails);89 });90 }91 return false;92 });93 if (o.userCollapse) {94 $this95 .find('span.details').append('<span class="re-collapse">' + o.userCollapsePrefix + '<a href="#">' + o.userCollapseText + '</a></span>');96 $this.find('span.re-collapse a').click(function() {97 clearTimeout(delayedCollapse);98 var $detailsCollapsed = $(this).parents('span.details');99 reCollapse($detailsCollapsed);100 o.onCollapse($this, true);101 return false;102 });103 }104 });105 function reCollapse(el) {106 el.hide()107 .prev('span.read-more').show();108 }109 function delayCollapse(option, $collapseEl) {110 if (option.collapseTimer) {111 delayedCollapse = setTimeout(function() { 112 reCollapse($collapseEl);113 option.onCollapse($collapseEl.parent(), false);114 },115 option.collapseTimer116 );117 }118 }119 function rSlash(rString) {120 return rString.replace(/\//,'');121 } 122 };123 // plugin defaults124 $.fn.expander.defaults = {125 slicePoint: 100, // the number of characters at which the contents will be sliced into two parts. 126 // Note: any tag names in the HTML that appear inside the sliced element before 127 // the slicePoint will be counted along with the text characters.128 widow: 4, // a threshold of sorts for whether to initially hide/collapse part of the element's contents. 129 // If after slicing the contents in two there are fewer words in the second part than 130 // the value set by widow, we won't bother hiding/collapsing anything.131 expandText: 'read more', // text displayed in a link instead of the hidden part of the element. 132 // clicking this will expand/show the hidden/collapsed text133 expandPrefix: '… ',134 collapseTimer: 0, // number of milliseconds after text has been expanded at which to collapse the text again135 expandEffect: 'fadeIn',136 expandSpeed: '', // speed in milliseconds of the animation effect for expanding the text137 userCollapse: true, // allow the user to re-collapse the expanded text.138 userCollapseText: '[collapse expanded text]', // text to use for the link to re-collapse the text139 userCollapsePrefix: ' ',140 beforeExpand: function($thisEl) {},141 afterExpand: function($thisEl) {},142 onCollapse: function($thisEl, byUser) {}143 };...
day10-2.js
Source:day10-2.js
1const path = require('path');2const fs = require('fs');3const input = fs.readFileSync(path.join(__dirname, 'input.txt'), 'utf8').trim().split('\n');4const startTags = ['(', '[', '{', '<'];5const endTags = [')', ']', '}', '>'];6let p2Points = [];7for (let i = input.length-1; i >= 0; i--) {8 let value = input[i];9 let start = [];10 let line = value.split('');11 for (let j = 0; j < line.length; j++) {12 let char = line[j];13 // end tag14 if (startTags.indexOf(char) === -1) {15 if (start.lastIndexOf(startTags[endTags.indexOf(char)]) !== start.length - 1) {16 // invalid end tag17 j = Infinity;18 // remove invalid line19 input.splice(i, 1);20 continue;21 } else {22 // start tag found, remove the start tag23 start.splice(start.lastIndexOf(startTags[endTags.indexOf(char)]), 1);24 }25 } else {26 // start tag27 start.push(char);28 }29 // if we're at the end, complete the tags30 if (j === line.length - 1) {31 p2Points.push(start.reverse().reduce((total, value) => { 32 return total * 5 + startTags.indexOf(value)+1;33 }, 0));34 }35 }36}...
Using AI Code Generation
1var wptools = require('wptools');2var options = {3};4var page = wptools.page('Barack Obama', options);5page.startTags(function(err, data) {6 console.log(data);7});8 var options = {9 };10 var page = wptools.page('Barack Obama', options);11 page.startTags(function(err, data) {12 console.log(data);13 });
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('India');3page.startTags(function(err, tags) {4 console.log(tags);5});6var wptools = require('wptools');7var page = wptools.page('India');8page.get(function(err, page) {9 console.log(page);10});11var wptools = require('wptools');12var page = wptools.page('India');13page.get(function(err, page) {14 console.log(page);15}, {16});17var wptools = require('wptools');18var page = wptools.page('India');19page.get(function(err, page) {20 console.log(page);21}, {22}, function(err, page) {23 console.log(page);24});25var wptools = require('wptools');26var page = wptools.page('India');27page.get(function(err, page) {28 console.log(page);29}, function(err, page) {30 console.log(page);31});32var wptools = require('wptools');33var page = wptools.page('India');34page.get(function(err, page) {35 console.log(page);36}, {
Using AI Code Generation
1var wptag = require('wptag');2var wp = new wptag();3wp.startTags();4var wptag = require('wptag');5var wp = new wptag();6wp.startTags();7var wptag = require('wptag');8var wp = new wptag();9wp.startTags();10var wptag = require('wptag');11var wp = new wptag();12wp.startTags();13var wptag = require('wptag');14var wp = new wptag();15wp.startTags();16var wptag = require('wptag');17var wp = new wptag();18wp.startTags();19var wptag = require('wptag');20var wp = new wptag();21wp.startTags();22var wptag = require('wptag');23var wp = new wptag();24wp.startTags();25var wptag = require('wptag');26var wp = new wptag();27wp.startTags();28var wptag = require('wptag');29var wp = new wptag();30wp.startTags();31var wptag = require('wptag');32var wp = new wptag();33wp.startTags();34var wptag = require('wptag');35var wp = new wptag();36wp.startTags();37var wptag = require('wptag');38var wp = new wptag();39wp.startTags();40var wptag = require('wptag');41var wp = new wptag();42wp.startTags();43var wptag = require('wptag');44var wp = new wptag();45wp.startTags();46var wptag = require('wptag');47var wp = new wptag();48wp.startTags();49var wptag = require('wptag');50var wp = new wptag();51wp.startTags();
Using AI Code Generation
1var wptag = require('wptag');2var wp = new wptag.WPTag();3wp.startTags(function(result){4 console.log(result);5});6var wptag = require('wptag');7var wp = new wptag.WPTag();8wp.endTags(function(result){9 console.log(result);10});11var wptag = require('wptag');12var wp = new wptag.WPTag();13wp.startTags(function(result){14 console.log(result);15});16var wptag = require('wptag');17var wp = new wptag.WPTag();18wp.endTags(function(result){19 console.log(result);20});21var wptag = require('wptag');22var wp = new wptag.WPTag();23wp.startTags(function(result){24 console.log(result);25});26var wptag = require('wptag');27var wp = new wptag.WPTag();28wp.endTags(function(result){29 console.log(result);30});31var wptag = require('wptag');32var wp = new wptag.WPTag();33wp.startTags(function(result){34 console.log(result);35});36var wptag = require('wptag');37var wp = new wptag.WPTag();38wp.endTags(function(result){39 console.log(result);40});41var wptag = require('wptag');42var wp = new wptag.WPTag();43wp.startTags(function(result){44 console.log(result);45});46var wptag = require('wptag');47var wp = new wptag.WPTag();48wp.endTags(function(result){49 console.log(result);50});51var wptag = require('wptag');52var wp = new wptag.WPTag();53wp.startTags(function
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!!