function isValidEmail(value) {
const len = value.length
const idx = value.indexOf('@')
return len >= 3 && idx > 0 && idx < len - 1;
}
console.log(isValidEmail('contact@example.com')); // true
console.log(isValidEmail('a@b')); // true
console.log(isValidEmail('@a')); // false
console.log(isValidEmail('b@')); // false
console.clear();
function saveCalls(func) {
const calls = [];
function proxy(...args) {
var ctx = this;
calls.push({
ctx: ctx,
args: args,
});
return func.apply(ctx, args);
}
proxy.calls = calls;
return proxy;
}
function sum(a, b) {
return a + b;
}
const saveSum = saveCalls(sum);
console.log(saveSum(5, 10));
console.log(saveSum(3, 1));
console.log(saveSum.calls);
const user = {
name: 'john',
say() {
return this.name;
},
};
const saveSay = saveCalls(user.say);
console.log(saveSay.call(user));
console.log(saveSay.calls);
RewriteRule "^/booking$" "/?booking" [R=301,L]
import React from "react";
import moment from "moment";
import 'moment/locale/ru'; // create-react-app specific
moment.locale("ru");
const target = moment("2020-08-17 23:00:00");
const toNow = target.toNow(true);
export default function App() {
return (
<div>
<p>Осталось {toNow}</p>
</div>
);
}
return { ...acc, [name]: arg }
var tmp = {};
tmp[name] = arg;
return Object.assing({}, acc, tmp);