{}[]"
. fetch(YOUR_URL, {
method: 'POST',
headers: {
'Client-Id': YOUR_CLIENT_ID,
'Api-Key': YOUR_API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
offer_id: YOUR_OFFER_ID,
product_id: YOUR_PRODUCT_ID,
sku: YOUR_SKU
})
}).then(response => response.json()).then(data => {
console.log(data);
});
package.json
, или .eslintrc.json
(все варианты тут). Так же и с prettier. deleteItem = (id) => {
this.setState(({ toDoData }) => ({
toDoData: toDoData.filter(entry => entry.id !== id)
}));
}
const prefixes = ['Inscribed', 'Autographed', 'Exalted', 'Corrupted'];
const prefixExpression = new RegExp(`^(${prefixes.join('|')})`, 'gi');
const items = [
{ name: 'Corrupted Demon Eater', price: '3215.00', inStock: 1 },
{ name: 'Exalted Demon Eater', price: '1530.00', inStock: 1 },
{ name: 'Demon Eater', price: '2900.00', inStock: 1 },
{ name: 'Whalehook', price: '1000.00', inStock: 1 },
{ name: 'Whalehook', price: '590.00', inStock: 1 },
{ name: 'Whalehook', price: '259.20', inStock: 1 },
{ name: 'Whalehook', price: '259.15', inStock: 1 },
{ name: 'Autographed Whalehook', price: '243.00', inStock: 1 },
{ name: 'Autographed Whalehook', price: '344.00', inStock: 1 },
{ name: 'Autographed Whalehook', price: '199.00', inStock: 1 },
{ name: 'Inscribed Whalehook', price: '355.00', inStock: 1 },
{ name: 'Inscribed Whalehook', price: '655.00', inStock: 1 },
{ name: 'Inscribed Whalehook', price: '5555.00', inStock: 1 },
{ name: 'Inscribed Sylvan Cascade', price: '345.00', inStock: 1 },
{ name: 'Inscribed Sylvan Cascade', price: '96.18', inStock: 1 },
{ name: 'Inscribed Sylvan Cascade', price: '95.00', inStock: 1 },
{ name: 'Inscribed Sylvan Cascade', price: '266.71', inStock: 1 },
{ name: 'Inscribed Sylvan Cascade', price: '85.00', inStock: 1 }
];
const getCheapest = items => {
const store = items.reduce((accumulator, item) => {
const type = item.name.replace(prefixExpression, '').trim();
if (!accumulator.has(type)) {
accumulator.set(type, []);
}
accumulator.get(type).push(item);
return accumulator;
}, new Map());
const cheapest = store.values().reduce((accumulator, items) => {
const minPrice = Math.min(...items.map(item => parseFloat(item.price)));
const item = items.find(item => parseFloat(item.price) === minPrice);
accumulator.push(item);
return accumulator;
}, []);
return cheapest;
};
getCheapest(items);
/*
[
{ name: 'Exalted Demon Eater', price: '1530.00', inStock: 1 },
{ name: 'Autographed Whalehook', price: '199.00', inStock: 1 },
{ name: 'Inscribed Sylvan Cascade', price: '85.00', inStock: 1 }
]
*/
<meta name="viewport" content="width=device-width, initial-scale=1.0">
function replacer(string, expression, mapper) {
return (string.match(expression) || []).map(mapper);
}
function match(rawNumber) {
let number = parseInt(rawNumber);
if (number >= 10 && number < 30) {
return 'Третий';
} else if (number >= 30 && number < 50) {
return 'Второй';
} else if (number >= 50 && number < 100) {
return 'Первый';
} else {
return 'Что-то';
}
}
console.log(replacer('80 75 85 90 10 30 0', /\d+/g, match));
// ['Первый', 'Первый', 'Первый', 'Первый', 'Третий', 'Второй', 'Что-то']
const urls = [
'/page/profile',
'/page/article/123123',
'/page/article/new',
'/page/article',
'/page/some/nested/structure/here',
'/page/module/article/new'
];
for (const url of urls ) {
const expression = /^\/page\/(.*)?(article)(.*)?$/g;
console.log(url, expression.test(url));
}
/*
'/page/profile' false
'/page/article/123123' true
'/page/article/new' true
'/page/article' true
'/page/some/nested/structure/here' false
'/page/module/article/new' true
*/
console.log(Object.fromEntries(formData.entries()));
console.log([...formData.entries()].reduce((accumulator, [key, value]) => {
accumulator[key] = value;
return accumulator;
}, {}));
const point = (x, y) => ({ x, y });
const A = point(-1, 1);
const B = point(1, 1);
const C = point(1, -1);
const D = point(-1, -1);
const E = point(0, 0);
const side = (a, b, p) => Math.sign((b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x));
const inArea = side(A, B, E) === -1 &&
side(B, C, E) === -1 &&
side(C, D, E) === -1 &&
side(D, A, E) === -1;
console.log(inArea); // true
function point(x, y)
return { ["x"] = x, ["y"] = y }
end
function sign(number)
if (number < 0) then
return -1
elseif (number > 0) then
return 1
else
return number
end
end
function side(a, b, p)
return sign((b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x))
end
A = point(-1, 1)
B = point(1, 1)
C = point(1, -1)
D = point(-1, -1)
E = point(0, 0)
inArea = side(A, B, E) == -1 and
side(B, C, E) == -1 and
side(C, D, E) == -1 and
side(D, A, E) == -1;
print(inArea) -- true
[0; 1]
, либо в интервале [-1; 1]
, в зависимости от реализации. Если найдете ту, которая возвращает числа в интервале [-1; 1]
, тогда превращаете в интервал [0; 1]
(полученное число делите на 2 и прибавляете 0.5) и умножаете на некий коэффициент. const clone = (base, count, key = 'id') => [...new Array(count)].map((_, index) => {
const cloned = { ...base };
cloned[key] += index;
return cloned;
});
const a = {
id: 7,
type: 'apple'
};
console.log(clone(a, 8));
console.log(a);
/**
[
{ id: 7, type: 'apple' },
{ id: 8, type: 'apple' },
{ id: 9, type: 'apple' },
{ id: 10, type: 'apple' },
{ id: 11, type: 'apple' },
{ id: 12, type: 'apple' },
{ id: 13, type: 'apple' },
{ id: 14, type: 'apple' }
]
{ id: 7, type: 'apple' }
*/