This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getEventsAction() { | |
const component = get_current_component(); | |
return node => { | |
const events = Object.keys(component.$$.callbacks); | |
const listeners = []; | |
events.forEach( | |
event => listeners.push( | |
listen(node, event, e => bubble(component, e)) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const letterExhange = { | |
a: 1, | |
b: 2, | |
c: 3, | |
d: 4, | |
e: 5, | |
f: 6, | |
g: 7, | |
h: 8, | |
i: 9, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This will return true if the value is some of the items | |
* @param {string} pkgName | |
* @param {string} functionName | |
* @param {function} callback | |
*/ | |
function npm(pkgName,functionName,callback){ | |
const http = new XMLHttpRequest(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onViewport(elem, callback, options = {}) { | |
if (elem instanceof Element) elem = [elem] | |
// Initial option | |
// Unobserve the element if it is on the viewport for optimizing purposes | |
const { abortEarly = true } = options | |
let counter = 0 | |
const observer = new IntersectionObserver((entries, self) => { | |
entries.forEach((el) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!String.prototype.includes){ | |
String.prototype.includes = function(value, fromIndex){ | |
return this.indexOf(value, fromIndex || 0) > -1 | |
} | |
} | |
if (!Array.prototype.includes){ | |
Array.prototype.includes = function(value, fromIndex){ | |
return this.indexOf(value, fromIndex || 0) > -1 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You can exclude this if you will not use it | |
HTMLCollection.prototype.forEach = function (callback, thisArg) { | |
Array.prototype.forEach.call(this, callback, thisArg || window) | |
} | |
if ('NodeList' in window && !NodeList.prototype.forEach) { | |
NodeList.prototype.forEach = function (callback, thisArg) { | |
Array.prototype.forEach.call(this, callback, thisArg || window) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function uuid(prefix = '', date = true) { | |
let counter = 0 | |
return { | |
create: () => { | |
return `${date ? Date.now().toString(16) : ''}${prefix}${counter++}` | |
}, | |
} | |
} | |
const uid = uuid('prefix') | |
console.log(uid.create()) // 176dc698f58prefix0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cConjecture(x) { | |
const result = [] | |
while (x > 1) { | |
if (x % 2 === 0) { | |
x = x / 2 | |
result.push(x) | |
} else { | |
x = x * 3 + 1 | |
result.push(x) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solution(list) { | |
const result = [] | |
let str = [] | |
for (let i = 0; i < list.length; i++) { | |
if (list[i + 1] === list[i] + 1) { | |
str.push(list[i]) | |
} else { | |
if (str.length < 2) { | |
result.push(...str, list[i]) | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function linearSolver(equation) { | |
const equa = equation.split('=').map((x) => x.replace(/\s/g, '')) | |
const hasX = equa.find((x) => /x/.test(x)) | |
const noX = equa.find((x) => !/x/.test(x)) | |
let x = 0 | |
const errorMsg = 'Invalid Equation: ' + equation | |
try { | |
if (/\b\W/.test(hasX)) { | |
const c = hasX.match(/(-|\+|)+(\d+x|x\d+)/)[0] |
NewerOlder