let a = ['Калинина 152, Москва, Россия', 'каленова 81, гдетов, россия'],
b = ['Калинина 152 домофон к2534 зовут Инокентий #827', 'Каленова 81 никого нет дома, оставить у двери #274']
const wccustoms = s => s.replace(/^[^,]*/, m => {
let r = new RegExp('^' + m,'i'),
v = b.find(v=>r.test(v))
return v ? v.substr(0,v.indexOf('#')) : m
})
for (addr of a)
console.log(wccustoms(addr))
const result = string2.substr(0,string2.indexOf('#'))+string1.substr(string1.indexOf(',',))
function a(index,value){
return new Promise((resolve,reject)=>{
let j = 0,
// этот тикер симулирует async фанкцию, т.е. ajax например
h = setInterval(_ => {
if (++j==2) {
clearInterval(h)
console.log('step '+index+' finished');
resolve(a(++index,j))
}
},1000);
});
};
a(0,0)
async function request(){
return new Promise(resolve=>setTimeout(_=>resolve(),1000))
}
( async () => {
for (i=0;i<5;i++){
const data = await request()
console.log('another way | step ' + i + ' complete')
}
})()
const addLetters= (...letters) => String.fromCharCode(letters.reduce((sum,v)=>sum+v.charCodeAt()-96,25) % 26 + 97)
function format(value){
let [a,b] = (+value.replace(/[^\d\.,]/g,'').replace(',','.')).toFixed(2).split('.')
c = a.replace(/(\d)(?=(\d{3})+(\D|$))/g, '$1 ')
return `${c},${b}`
}
console.log(format('12734,589'))
// 12 734,59
console.log(format('1 2 7 3s4.5'))
// 12 734,50
console.log(format('12734'))
// 12 734,00
<input type="text" id='price' placeholder="12 345,90" required pattern="^\d{1,3}(\s?\d{3})*([\.,]\d+)?$" />
<form id="thatMustBeFilled">
<input type='text' value='7' class="notEmpty" required>
<input type='text' value='' class="notEmpty" required>
</form>
const valid = _ => document.querySelectorAll('form#thatMustBeFilled>input.notEmpty:invalid').length == 0
console.log(valid())
//false
expect.extend({
toBeInList(received, ...values) {
const pass = values.includes(received),
message = `expected ${received}${ pass ? '' : ' not'} equals ${values.join(" or ")}`
return {
message: () => message,
pass
}
});
expect(result.aaa).toBeInList(a, b);
document.querySelectorAll('span.oldvalue').forEach(function(node){
node.addEventListener('click', function(event){
let span = event.target,
input = span.previousSibling
if (!input.dataset.default) input.dataset.default = input.value
input.value = input.value === input.dataset.default ? span.innerText : input.dataset.default
})
})
function addLetters(...letters){
let alphabet = 'abcdefghijklmnopqrstuvwxyz',
len = alphabet.length,
sum = len - 1// по умолчанию 'z'
for (i=0;i<letters.length;i++)
sum += alphabet.indexOf(letters[i]) + 1 // счет начинается с 1 (a=1)
return alphabet.substr(sum % len,1)
}
const addLetters= (...letters) => String.fromCharCode(letters.reduce((sum,v)=>sum+v.charCodeAt()-96,25) % 26 + 97)
$scope.ruLoanApproval = _ => $scope.loanApproval === 'DENIED' ? 'Отказано' : 'Одобрено'
$scope.loanApproval = response.data.approval === 'DENIED' ? 'Отказано' : 'Одобрено'
console.log(typeof([]))
//Object
console.log(Object.prototype.toString.call( { } ).indexOf('object Object') ==1)
//true
console.log(Object.prototype.toString.call( [ ] ).indexOf('object Object') ==1)
//False
const isObject = objRef => Object.prototype.toString.call( objRef ).indexOf('object Object') == 1
Math.Fibonacci = new function(cacheSize = 10){
var _current = 0, _cache = [], C = cacheSize
const A = 5 ** 0.5,
B = (1 + A) / 2,
LNb = Math.log( B ),
Y = x => cache.add( [ x, Math.round( B ** x / A ) ] )[ 1 ],
R = [ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 ],
X = y => Math.log( A * y ) / LNb,
cache = {
add: ( xy ) => {
if ( _cache.length == C ) _cache = _cache.slice(1,)
_cache.push(xy)
return xy
},
get: n => n in R ? R[n] : ( ( _i = _cache.findIndex(e=>e[0]==n)) != -1 ? _cache[_i][1] : null ),
find: x => ( _i = R.indexOf(x) ) != -1 ? _i : ( ( _i = _cache.findIndex(e=>e[1]==x)) != -1 ? _cache[_i][0] : null )
}
this.get = n => ( _value = cache.get( n ) ) !== null ? _value : Y( n );
this.find = x => {
if ( ( _value = cache.find( x ) ) !== null ) return _value
let a = this.adjacent( x );
return a[0][1] == x ? a[0][0] : ( a[1][1] == x ? a[1][0] : -1 )
}
this.adjacent = y => {
let x = X(y),
x1 = Math.floor(x),
x2 = Math.ceil(x),
y1 = Y(x1),
y2 = Y(x2);
if ( y1 == y ) return [ cache.add( [x1,y1] ), [x1,y1] ]
else if ( y2 == y ) return [ cache.add( [x2,y2] ), [x2,y2] ]
else return [ cache.add( [ x1, y1 ] ), cache.add( [ x2, y2 ] ) ]
}
this.setCacheSize = l => l > 0 ? C = l : false
this.next = _ => Y( ++_current )
this.prev = _ => Y( --_current )
this.current = _ => Y( _current )
}
console.log( Math.Fibonacci.adjacent(20) )
// [ [7, 13], [8,21] ]
let x = 20,
[ [_,min], [__,max] ] = Math.Fibonacci.adjacent( x )
x = min === max ? x : max;
console.log(x)
//21
let s = "https://domen.com/path/path2MK/?search.",
i = s.lastIndexOf('/');
console.log( s.substr(i-2,2) )
let a = "1_5_3_3_4", b = "3-1_7_4_5",
c = s => s.replace(/-\d+/g, '').split("_"),
d = c(b),
x = c(a).reduce( (n,e) => {
if(d.indexOf(e) >= 0){
delete d[d.indexOf(e)]
n++
}
return n
}, 0 );
console.log(`Найдено совпадений: ${ x }`);
// Найдено совпадений: 3
const company_data = () => new Promise((resolve,reject) => {
pool.query(`select * from the_company where creator_id = ?`, {creator_id}, (error,results,fields) => {
const id = results.map(r => r.id)
const name = results.map(r => r.name) //Ответ - { id: '41' } - id
console.log(`${id} - id`)
resolve(id)
})
})
var productCounter = { a: 0 }
function incrementCounter(counter) {
counter.a++
console.log(counter.a)
}
incrementCounter(productCounter)
console.log(productCounter.a)
console.log( JSON.stringify(object) )