function getCombination(arr, n) {
const sortedArr = JSON.parse(JSON.stringify(arr)).sort();
const results = [];
const part = [];
for(let i = 0; i < sortedArr.length; i++) {
part.push(sortedArr[i]);
const summ = part.reduce((a, b) => a + b);
if (summ === n) {
results.push([...part]);
}
if (summ > n) {
part.pop();
i = sortedArr.indexOf(part[part.length - 1]);
part.pop();
}
}
return results;
}
console.log(getCombination([7, 8, 3, 4, 5, 6, 1, 2], 8));
// [[1, 2, 5], [1, 3, 4], [1, 7], [2, 6], [3, 5], [8]]
(async function() {
var blob = await (await fetch('https://dr.habracdn.net/qna/637b1a73/images/favicons/apple-touch-icon-180x180.png')).blob();
var file = new File([ blob ], 'Favicon.png', { type: blob.type });
console.log(file);
})();
console.log('инфа по браузеру',navigator.userAgentData);
console.log('батарея',await navigator.getBattery());
console.log('местоположение',await navigator.geolocation.getCurrentPosition())
console.log('ip', await fetch('https://ipinfo.io',{credentials:'omit'}).then(res=>res.json()));
\.[a-z][a-z-]+
getUsers() .then((users) => (this.users = users)) .then(() => getOrganizations()) .then((organizations) => (this.organizations = organizations)) .then(() => this.setState({ loading: false }));
if (this.state.loading) { return "Loading..."; } let users = []; for (let i = 0; i < this.users.length; i++) { const name = this.users[i].name; let org; for (let j = 0; j < this.organizations.length; j++) { if (this.organizations[j].id === this.users[i].organization) { org = this.organizations[j].name; } } users.push( <div className="user-list-item"> <div>name: {name}</div> <div onClick={() => this.selectOrg(org)}>org: {org}</div> </div> ); }
{this.state.selectedOrg && <button onClick={() => this.resetSelectedOrg()}>reset selected org</button>}
for (let j = 0; j < this.organizations.length; j++) { if (this.organizations[j].id === this.users[i].organization) { org = this.organizations[j].name; } }
for (let i of arr)
arr.reduce((acc, n) => (
n = n.match(/(\S+) = (.*)/),
n && (acc[n[1]] = n[2]),
acc
), {})
const parseArrayOfLines = (arrayOfLines) => {
const result = {};
try {
arrayOfLines.forEach((line) => {
const lineTokens = line.split(' ');
const equalsPosition = lineTokens.indexOf('=');
const isValidLine = equalsPosition !== -1;
if (!isValidLine) {
return;
}
const keyPosition = equalsPosition - 1;
const valuePosition = equalsPosition + 1;
result[lineTokens[keyPosition]] = lineTokens[valuePosition];
});
} catch (error) {
//
} finally {
return result;
}
};