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 bufer = (function makeBufer() { | |
let cash = ''; | |
function fn(value) { | |
if (!value) { | |
return cash; | |
} | |
cash += value; | |
} | |
fn.clear = () => { |
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 makePeople(count) { | |
let people = []; | |
let serialNumber = 0; | |
for (; serialNumber < count; serialNumber++) { | |
let men = (num) => { | |
return () => { | |
debugger | |
console.log(num) | |
}; |
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
_imageEncode(arrayBuffer, contentType) { | |
let u8 = new Uint8Array(arrayBuffer) | |
let b64encoded = btoa([].reduce.call(new Uint8Array(arrayBuffer), function (p, c) { return p + String.fromCharCode(c) }, '')) | |
let mimetype = contentType || "image/png" | |
return "data:" + mimetype + ";base64," + b64encoded | |
} |
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
switch (digitsOnly) { | |
case digitsOnly.match(/\s+/g) ? digitsOnly : true: | |
result = digitsOnly.replace(/\s+/g, '');/* оставляем только цифры, удаляем пробелы*/ | |
break; | |
case digitsOnly.match(/\.+/g) ? digitsOnly: true: | |
result = digitsOnly.replace(/\.+/g, '');/* оставляем только цифры, удаляем точки*/ | |
break; | |
case digitsOnly.match(/^\d+/g) ? digitsOnly: true: | |
result = digitsOnly.replace(/\s+/g, '');/* оставляем только цифры, удаляем пробелы*/ | |
break; |
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 randomInteger(min, max) { | |
// случайное число от min до (max+1) | |
let rand = min + Math.random() * (max + 1 - min); | |
return Math.floor(rand); | |
} | |
console.log( randomInteger(1, 3) ); |
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
async function sendCASH() { | |
let promise = new Promise((resolve, reject) => { | |
setTimeout(() => resolve('Ok, nice!'), 3000); | |
setTimeout(() => reject('Fuck, shit!'), 4000); //не сработает | |
}); | |
let result = await promise; | |
return result; | |
} | |
sendCASH() |
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 funcLol(params) { | |
this.timeOut ? clearTimeout(this.timeOut) : null | |
this.timeOut = setTimeout(() => { | |
console.log('post', params); | |
}, 1000); | |
} |
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 const createContactsArray = (keys, values, len) => { | |
let i, arr = [] | |
for (i = 1; i <= len; i++) { | |
let obj = {} | |
for (let index = 0; index < keys.length; index++) { | |
obj[keys[index]] = keys[index] === 'id' ? `00${i + index}` : values[index] | |
} | |
arr.push(obj); | |
} | |
return arr; |
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 str = 'some string' | |
str.replace(/[ .,\/#!$%\^&\*;:{}=\-_`~()]/g, '_'); //удалит все знаки и пробел |
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 primality(n) { | |
for(let i = 2; i < n; i++) { | |
if(n % i === 0) return false; | |
} | |
return n > 1; | |
} |
OlderNewer