const mustStay = arr => arr.every(n => n.value !== '-');const newArr = arr.filter(mustStay);
// или
const newArr = [];
for (const n of arr) {
if (mustStay(n)) {
newArr.push(n);
}
}
// или
const newArr = [];
for (let i = 0; i < arr.length; i++) {
if (mustStay(arr[i])) {
newArr[newArr.length] = arr[i];
}
}
// или
const newArr = (function get(i, n = arr[i]) {
return n
? [ mustStay(n) ? [ n ] : [], get(i + 1) ].flat()
: [];
})(0)for (let i = 0; i < arr.length; i++) {
if (!mustStay(arr[i])) {
for (let j = i--; ++j < arr.length; arr[j - 1] = arr[j]) ;
arr.pop();
}
}
// или
arr.reduceRight((_, n, i, a) => mustStay(n) || a.splice(i, 1), null);
// или
arr.splice(0, arr.length, ...arr.filter(mustStay));
// или
arr.length -= arr.reduce((acc, n, i, a) => (
a[i - acc] = n,
acc + !mustStay(n)
), 0);
if (
document.getElementById('apple').style.display == 'none' &&
document.getElementById('shoe').style.display == 'none' &&
document.getElementById('book').style.display == 'none' &&
document.getElementById('purse').style.display == 'none'
) {
document.getElementById('begin').style.display = 'none';
}
class A:
pass
a = A()
a.x = 1
print(a.x, a.__getattribute__('x'))
a.__setattr__('from', 2) # вот же идиотизм
print(a.__getattribute__('from')) import math
import os
INPUT_FILE = 'input.txt'
OUTPUT_FILE = 'output.txt'
NUMBER_THRESHOLD = 1000
if __name__ == '__main__':
if not os.path.exists(INPUT_FILE) or not os.path.isfile(INPUT_FILE):
raise FileNotFoundError
with open('input.txt') as file:
text = file.read()
if not text:
raise ValueError('File is empty')
try:
a, b, c, *_ = [int(n) for n in text.strip().split(" ") if n.isdigit() and int(n) < NUMBER_THRESHOLD]
except ValueError:
raise ValueError('Wrong input data')
out = ""
if not (a < b + c and b < a + c and c < a + b):
out = "-1"
else:
p = 0.5 * (a + b + c)
h = 2 * math.sqrt(p * (p - a) * (p - b) * (p - c)) / a
out = f'{str(a + b + c)} {("%.5f" % (a * h / 2))}'
with open(OUTPUT_FILE, 'w') as file:
file.write(out)
const objectParser = (data, path = '') =>
Object.assign(
{ [path || '<root>']: data },
...(data instanceof Object
? Object.entries(data).map(([ k, v ]) => objectParser(v, `${path}[${k}]`))
: []
)
);function objectParser(data) {
const result = {};
for (const stack = [ [ data, '' ] ]; stack.length;) {
const [ n, path ] = stack.pop();
result[path || '<root>'] = n;
(n instanceof Object) && Object
.entries(n)
.reverse()
.forEach(([ k, v ]) => stack.push([ v, `${path}[${k}]` ]));
}
return result;
}
if (typeof defaultBg1 == 'Background') // ???null и undefined свойств не бывает, попытка обратиться к конструктору в их случае приведёт к TypeError; кроме того, instanceof проверяет всю цепочку прототипов, т.е., например, [ 1, 2, 3 ] одновременно и instanceof Array, и instanceof Object):if (defaultBg1 instanceof Background)
// или
if (defaultBg1.constructor === Background)
// или
if (defaultBg1.constructor.name === 'Background')const type = x => x == null ? `${x}` : x.constructor.name;
type() // 'undefined'
type(null) // 'null'
type(true) // 'Boolean'
type(69) // 'Number'
type('hello, world!!') // 'String'
type(/./) // 'RegExp'
type([ 187 ]) // 'Array'
type({ z: 666 }) // 'Object'
type(document) // 'HTMLDocument'
type(document.querySelectorAll('div')) // 'NodeList'
type(new class XXX {}) // 'XXX'
type(type) // 'Function'