Skip to content

Instantly share code, notes, and snippets.

const moving = (element, emptyCell) => {
const oldNode = element.childNodes[0];
element.removeChild(oldNode);
element.setAttribute('class', 'p-3 table-active');
emptyCell.setAttribute('class', 'p-3');
emptyCell.append(oldNode);
return;
};
@tuor4eg
tuor4eg / doc.js
Last active August 22, 2018 12:18
export default () => {
// BEGIN (write your solution here)
const makeActive = (element) => {
const link = element.getAttribute('href').substr(1);
const currentTab = element.parentNode.parentNode.getElementsByClassName('nav-link active')[0];
const currentLink = currentTab.getAttribute('href').substr(1);
const currentDiv = document.getElementById(link);
const findDiv = document.getElementById(link);
currentDiv.setAttribute('class', 'tab-pane');
findDiv.setAttribute('class', 'tab-pane active');
const readFileAsync = file => new Promise((resolve, reject) => {
fs.readFile(file, (err, data) => err ? reject(err) : resolve(data));
});
const records = async () => {
const readBook = await readFileAsync('phonebook.txt');
const count = readBook.toString().split('\n').length - 1;
return `Welcome to The Phonebook\nRecords count: ${count}`;
};
БЫЛО:
const getToken = body => body.match(/value="(\w+)"/)[1];
export default (registrationFormUrl, submitFormUrl, nickname, callback) => {
// BEGIN (write your solution here)
const {protocol, hostname, path, pathname, port} = url.parse(submitFormUrl);
http.get(registrationFormUrl, res => {
const body = [];
res.on('data', chunk => {
export default (backendUrl, currentUrl) => {
return new Promise((resolve, reject) => {
get(backendUrl)
.then(response => {
if (response.status !== 200) {
reject(new Error(response.status));
return;
}
const parseJs = JSON.parse(response.data);
Promise.all(parseJs.map(element => {
export default (queryPar) => {
const postData = querystring.stringify(queryPar.data);
const { protocol, hostname, pathname, port, query } = url.parse(queryPar.url, true);
const options = {
protocol,
host: hostname,
path: `${pathname}${getSearch(query, queryPar.params)}`,
port,
method: queryPar.method,
headers: {
const noop = () => {};
const once = (fn) => {
let called = false;
return (...args) => {
if (called) return;
called = true;
fn(...args);
};
const noop = () => {};
const once = (fn) => {
let called = false;
return (...args) => {
if (called) return;
called = true;
fn(...args);
};
const propertyActions = [
{
name: 'body',
check: arg => typeof arg === 'string',
},
{
name: 'children',
check: arg => arg instanceof Array,
},
{
const getAttr = (attrib) => {
if (attrib.length === 0) {
return [];
}
const keys = Object.keys(attrib);
return keys.map(element => ` ${element}="${attrib[element]}"`).join('');
};
const makeObj = {
tag: [],