Данный отчёт сгенерирован 10.02.2023 18:21:31 UTC.
HTML версия (этот сайт) сгенерирован 10.02.2023 18:21:38 UTC.
Коммит: [bfeb65b9] add automatic zip creation 10.02.2023 18:21:31
HTML версия (этот сайт) сгенерирован 10.02.2023 18:21:38 UTC.
Коммит: [bfeb65b9] add automatic zip creation 10.02.2023 18:21:31
Задача: Розташувати Впереміжку
10.02.2023 18:21:31
Описание: Заданий масив логічних значень.
Чи можна так розташувати значення в масиві, щоб поруч не стояло двох однакових.
Визначте функцію test, яка отримає масив і повертає true, якщо таке можливе,
і false, якщо не можливе.
10.02.2023 18:21:31
Решений: 95
10.02.2023 18:21:31
Розташувати Впереміжку
10.02.2023 18:21:31
function test(arr){
let s_tr=0;
let s_fa=0;
for(let i = 0; i < arr.length;i++)
{
if(arr[i]===true)
{
s_tr++
}
if(arr[i]=== false)
{
s_fa++
}
}
if(s_tr-s_fa > 1 || s_fa - s_tr > 1)
{
return false
}
else true
}
function test(arr){
let t=0
let f=0
for(const elem of arr){
if(elem){
t++
}else{
f++
}
}
return Math.max(t,f)<=Math.ceil(arr.length/2)
}
function test(arr)
{
let t = 0, f = 0;
for (let el of arr) {
if (el == true) t++;
if (el == false) f++;
}
if (t-f > 1 || f-t > 1) return false;
else return true
}
function test(arr){
let countTrue = 0;
let countFalse = 0;
arr.forEach(bool => {
if(bool == true){
countTrue++;
}else {
countFalse++;
}
});
if(countFalse == countTrue || countFalse == countTrue - 1 || countFalse == countTrue + 1){
return true;
}else {
return false;
}
}
function test(arr){
let fcount = 0,
tcount = 0;
for (let i = 0; i < arr.length; i++){
if (arr[i]) tcount ++;
else fcount ++;
}
if (-1 <= tcount - fcount && tcount - fcount <= 1) return true;
else return false;
}
function test(arr){
if(arr.length == 0) return false;
let t = 0, f = 0;
for(let i = 0; i < arr.length; i++){
if (arr[i]) t += 1;
else f += 1;
}
if (t == f || t - f == 1 || f - t == 1) return true;
return false;
}
function test(arr){
let j=0
if (arr.length>1) {
for(let i=0; i< arr.length; i++){
if(arr[i]) j++
}
if((j-(arr.length-j))>=2 || ((arr.length-j)-j)>=2) {
return false
} else{
return true
}
}
}
function test(arr) {
let t = 0;
for(let v of arr) {
if(v) t += 1;
}
let l = arr.length;
return t <= (l + l%2) / 2 && t >= (l - l % 2)/2;
}
function test(x)
{
if (typeof x === "function") {
return('function');
}
if (Array.isArray(x)){
return 'array'
}
if (typeof x === "object"){
return 'object'
}
return 'other'
}
function test(arr){
}
function test(arr)
{
let a = 0
let b = 0
for(i=0; i< arr.length; i++)
{
if(arr[i]==true)
{
a++
}
else
{
b++
}
}
if(a==b||a==b+1||a==b-1)
{
return true
}
else
{
return false
}
}
function test(arr) {
const tL = arr.filter(el => el).length;
return Math.abs(arr.length - 2*tL) <= 1;
}
function test(arr) {
let tc = 0
let fc = 0
for (i = 0; i < arr.length; ++i) {
if (arr[i] == true) tc += 1
if (arr[i] == false) fc += 1
}
if (tc == fc || fc - 1 == tc || tc - 1 == fc) return true
else return false
}
function test(arr) {
let trueCount = 0;
let falseCount = 0;
for (let i = 0; i < arr.length; i++) {
if(arr[i]==true){trueCount++}
else if(arr[i]==false){falseCount++}
}
if (trueCount - falseCount >= -1 && trueCount - falseCount <= 1) {
return true
}
else return false
}
function test(arr)
{
let countTrue = 0;
for(let i = 0; i < arr.length; i++)
{
if(arr[i] == true)
countTrue++;
}
if((2*countTrue) - arr.length >= -1 && (2*countTrue) - arr.length <= 1)
return true;
else
return false;
}
function test(arr){
col_true = 0 ;
col_false= 0;
for (let x in arr){
if (arr[x]===true){
col_true=col_true+1
}
else{
col_false=col_false+1
}
}
}
function test(arr) {
console.log('Антелопа')
}
function test(arr){
let true_counter = 0;
let false_counter = 0;
for(let each of arr){
if(each == true){
true_counter++;
}else{
false_counter++;
}
}
if(true_counter - false_counter == 1 || true_counter - false_counter == -1 || true_counter == false_counter){
return true;
}else{
return false;
}
}
function test(arr){
let a = 0;
let b = 0;
for (let i = 0; i< arr.length; i ++){
if (arr[i] == true){
a++;
}
else{
b++;
}
}
if (a - 1 > b || b - 1 > a){
return false;
}
else {
return true ;
}
}
function test(arr)
{
let c1 = 0
let c2 = 0
for (let i = 0;i < arr.length;i++)
{
arr[i] && c1++
}
for (i = 0; i < arr.length;i++)
{
arr[i] || c2++
}
let t = c1 === c2 || c1-c2 === 1 || c1-c2 === -1
return t
}
function test(arr){
console.log('pika')
}
function test(arr){
let n = 0;
let m = 0;
for(let i = 0; i < arr.length; i++){
if(arr[i] == true){
++n;
}else{
++m;
}
}
let result = (n == m || n == m + 1) ? true : false;
return result;
}
function test(arr){
console.log('bebra')
}
function test(arr){
let t = 0;
let f = 0;
for(let i = 0; i < arr.length; i++){
if (arr[i] == true)
t++;
else
f++;
}
if (t - f == 1 || t - f == -1 || t - f == 0)
return true;
else
return false;
}
function test(arr) {
let tr = 0, fl = 0;
for (let i = 0; i < arr.length; i++) {
if (Boolean(arr[i]) === true)
tr++;
else
fl++;
}
if (tr > (fl+1) || fl > (tr+1))
return false;
else
return true;
}
function test(arr) {
let sumTrue = 0;
let sumFalse = 0;
for (let i = 0; i < arr.length; i++) {
if (arr[i] === true) {
sumTrue ++;
} else {sumFalse ++;}
}
if ((sumTrue % 2 != 0) && (sumFalse % 2 == 0) || (sumTrue % 2 == 0) && (sumFalse % 2 != 0)) {
return true;
} else if ((sumTrue % 2 == 0.5) && (sumFalse % 2 == 0.5)) {
return false;
}
}
function test(arr) {
let diff = arr.length - 2 * arr.filter(a => a).length;
return diff <= 1 && diff >= -1;
}
function test(arr){
let anull =0;
for(let i=0;i< arr.length;i++){
if(arr[i] == true){
anull++;
}
}
if(anull==arr.length-anull||anull==arr.length+1-anull){
return true;
}
else {
return false;
}
}
function test(arr){
console.log('sanya eto bober')
}
function test ( arr ) {
let a = 0
let b = 0;
for(let i = 0; i < arr.length; i++) {
if ( arr [ i ] ) {
a++;
}
else
b++;
}
return a == b || a == b + 1 || a == b - 1;
}
function test ( arr ) {
let a = 0
let b = 0;
for(let i = 0; i < arr.length; i++) {
if ( arr [ i ] ) {
a++;
}
else
b++;
}
return a == b || a == b + 1 || a == b - 1;
}
function test(arr){
let count1 = 0
let count2 = 0
for (let i = 0; i< arr.length; i++){
if (arr[i]==true){
count1 ++
}
else{count2++}
}
if (count1==count2){
if (count1-count2 < 2){
return true
}
}
if (count1>count2){
if (count1-count2 < 2){
return true
}
}
if (count2>count1){
if (count2-count1 < 2){
return true
}
}
return false
}
function test(arr) {
const test = arr => arr.every((val, i) => val !== arr[i+1]);
}
function test(array){
let counter = array.length;
// пока есть елементы
while (counter > 0) {
// выбрать случайный индекс
let index = Math.floor(Math.random() * counter);
// уменьшить счетчик на 1
counter--;
// и поменять последний елемент
let temp = array[counter];
array[counter] = array[index];
array[index] = temp;
}
return array;
}
function test(arr){
let obj = {};
let maxRepeat = 0;
for(let i of arr){
if(obj[i]){
obj[i]++;
}
else{
obj[i] = 1;
}
}
console.log(obj)
for(let i in obj){
if (obj[i] > maxRepeat){
maxRepeat = obj[i]
}
}
console.log(maxRepeat)
if (maxRepeat > Math.round(arr.length/2)) return false;
return true;
}
function test(arr)
{
let f=0, t=0
for(let i = arr.length-1; i>=0;i--)
if(arr[i]==1)
t++
else f++
return Math.abs(t-f)< 2
}
function test(arr) {
let numbersOfTrue = 0;
let numbersOfFalse = 0;
for(i = 0; i < arr.length; i++) {
if (arr[i] == true) {
numbersOfTrue++;
} else if (arr[i] == false) {
numbersOfFalse++;
}
}
if(numbersOfTrue == numbersOfFalse || numbersOfTrue - 1 == numbersOfFalse || numbersOfTrue + 1 == numbersOfFalse) {
return true;
} else {
return false;
}
}
function test(arr){
}
function test(arr){
let t = 0, f = 0;
for (let i of arr){
console.log(i)
if (i == 1) t++;
if (i == 0) f++;
}
if (Math.abs(t-f) >=0 && Math.abs(t-f) <= 1) return true;
else return false;
}
function test(arr)
{
arr.sort();
let f=0;
for(let el in arr)
if(arr[el]==false)
f++
else
break;
let t = arr.length-f;
if(arr.length%2==1){
if(t==f+1 || f==t+1)
return true;
else
return false;
}
else{
if(t==f)
return true;
else
return false;
}
}
function test(arr){
console.log("Denis")
}
function test(arr) {
}
function test(arr){
let b=0;
for(i=0;i< arr.length;i++){
let t=1
for(j=i+1;j< arr.length;j++){
if(arr[i]==arr[j]) t++
}
b=Math.max(b,t)
}
if(b<(arr.length/2)+1){
return true
}
return false
}
function test(arr){
let count1 = 0;
let count2 = 0;
for( let i = 0; i < arr.length; i++){
if(arr[i] == true){
count1++;
}
if(arr[i] == false){
count2++;
}
}
if(count1 == count2){
return true;
}
if(count1 == count2 + 1 || count2 == count1 + 1){
return true;
}
else{
return false;
};
}
function test(arr){
let countT = arr.filter(x=>x==true).length
let countF = arr.filter(x=>x==false).length
return console.log(countF,countT)
if(countF==countT || countF-countT==1|| countT-countF==1){
return true
}
return false
}
function test(arr)
{
let counterTrue = 0;
let counterFalse = 0;
for(i = 0; i < arr.length; i++)
{
if(arr[i] == true)
{
counterTrue += 1;
}
if(arr[i] == false)
{
counterFalse += 1;
}
}
if(counterFalse == counterTrue-1 || counterTrue == counterFalse-1 || counterFalse == counterTrue)
{
return true;
}
else
{
return false;
}
}
function test(arr)
{
let trueN = 0;
let falseN = 0;
for(let i = 0;i< arr.length;i++)
{
if(arr[i] == false) falseN++;
else trueN++
}
if(Math.abs(trueN-falseN)>1) return false;
return true;
}
function test(arr)
{
let counterTR=0;
let counterFal=0;
for(let i =0; i if(arr[i]== true){
counterTR+=1
}
else if(arr[i]== false){
counterFal+=1
}
}
if(counterTR-counterFal==1 || counterFal-counterTR==1 || counterFal-counterTR==0){
return true
}else{
return false
}
}
const test = (array) => (`Почини задачу`)
function test(arr)
{
let pos = 0;
let neg = 0;
for(let i = 0; i < arr.length; i++){
if(arr[i]){
pos++;
}else {
neg++;
}
}
return pos == neg || pos == neg +1 || pos == neg-1;
}
function test(arr){
}
function test(arr)
{
let counter = 0;
for (let i = 0; i < arr.length; i++)
{
if (arr[i] == true)
counter++;
else if (arr[i] == false)
counter--;
}
if (counter == 0 || counter == -1 || counter == 1)
return 1;
return 0;
}
function test(arr){
a=0;
b=0;
for (let i=0; i< arr.length; i++)
{
if(arr[i]==true)
a++;
else
b++;
}
return a==b-1 || a==b || a==b+1;
}
function test(arr){
let new_array = {};
for(let i = 0; i < arr.length; i++){
let el = arr[i];
if (new_array[el] != undefined){
new_array[el]++;
}
else{
new_array[el] = 1
}
}
let arr_el = Object.values(new_array)
for(let count = 0; count < arr_el.length; count++){
let g = count + 1;
if((arr_el[count] == arr_el[g])||(arr_el[count] - 1 == arr_el[g])||(arr_el[count] == arr_el[g] - 1)){
return true
}
else{
return false
}
}
}
function test(arr) {
console.log('Антелопа')
}
function test(arr) {
console.log('Kyky')
}
function test(arr) {
console.log('Антелопа')
}
function test(arr) {
let sum1 = 0;
for (let e of arr ) {
if (e) sum1 ++;
else sum1 --;
}
return Math.abs(sum1)<= 1;
}
function test(arr) {
console.log('Антелопа')
}
function test(arr){
let ifTrue = true;
let truecounter = 0;
let falsecounter = 0;
for (let i = 0; i< arr.length; i++){
if(arr[i]){truecounter++}
else{falsecounter++}
}
if ((truecounter-falsecounter)>1 || (falsecounter-truecounter)>1){ifTrue=false}
return ifTrue
}
function test(arr) {
let t = 0;
let f = 0;
for (let i = 0; i < arr.length; i++) {
if (arr[i] == true) t++;
else f++;
}
if (Math.abs(t-f) < 2) return true;
else return false;
}
function test(arr){
let countTrue = 0
let countFalse = 0
for (let i = 0; i < arr.length; i++){
if (arr[i] == true)
countTrue++
else
countFalse++
}
if (countTrue - countFalse >= 2 || countFalse - countTrue >= 2)
return false
else
return true
}
function test(arr) {
let countTrue = 0;
let countFalse = 0;
for (let i = 0; i < arr.length; i++)
if (arr[i]) countTrue++;
else countFalse++;
return Math.abs(countTrue - countFalse) <= 1;
}
function test (arr) {
let i = 0
for (let element of arr) {
if (element == true) i++
}
return Math.ceil(arr.length / 2) == i
}
function test(arr){
let nt = 0;
for (let value of arr){
if (value == true) nt++;
}
return (arr.length - 2*nt >= -1 && arr.length - 2*nt <= 1);
}
function test(arr)
{
let t = 0;
for(let i = 0; i if(arr[i]){
t++;
}
}
return Math.abs(arr.length-2*t)<=1;
}
function test(arr){
let T = 0, F = 0;
for(let i = 0; i < arr.length; i++)
{
if(arr[i])
T++;
else
F++;
}
if(module(T - F) < 2)
return true;
return false;
}
function module(num)
{
if(num < 0)
num *= -1;
return num;
}
function test(arr){
result = arr.reduce((acc, value) => acc = (value)? acc+1 : acc-1 , 0)
return (result <= 1 && result >= -1)? true:false;
}
function test(x) {
if (Array.isArray(x) == true) {
return 'array'
}
if (typeof (x) == 'function') {
return 'function'
}
if (typeof (x) == 'object') {
return 'object'
}
else {
return 'other'
}
}
function test(arr){
trueCount = 0;
falseCount = 0;
arr.forEach(el=>{if(el == true){trueCount++}else{falseCount++}});
if(trueCount === falseCount || trueCount === falseCount+1 || trueCount+1 === falseCount){
return true;
}
return false;
}
function test(arr) {
let a = 0
let b = 0;
for(let i = 0; i < arr.length; i++) {
if (arr[i]) {
a++;
}
else {
b++;
}
}
return a == b || a == b+1 || a == b-1;
}
function test(arr)
{
}
function test(arr){
let count_true=0;
let count_false=0;
for (let i = 0; i< arr.length; i++){
if(arr[i]==true){
count_true+=1
}
else if(arr[i]==false){
count_false+=1
}
}
if(count_false==0 || count_true==0){
return false
}
else if(arr.length==3){
return true
}
else if((Math.max(count_true, count_false)/Math.min(count_true, count_false))< 2){
return true
}
else{
return false
}
}
function test(arr){
let t=0,f=0;
for(let i =0;i< arr.length;i++){
if(arr[i]==false){f++;}
else if(arr[i]==true){t++;}
}
if(t==f||t-1==f||t+1==f){return true;}
else{return false}
}
function test(arr) {
let a = 0, b = 0;
for(let i = 0; i < arr.length; i++) {
if (arr[i]) a++;
else b++;
}
return a == b || a == b+1 || a == b-1;
}
function test(arr) {
let c = {};
for(e of arr) {
if(!(e in c))
c[e] = 0
c[e]++;
}
let val = Object.values(c);
if(val.includes(0))
return false;
else if(arr.length == 3)
return true;
return Math.max(...val)/Math.min(...val) < 2;
}
function test(arr){
tr = arr.filter(x => x==true).length
fal = arr.filter(x => x==false).length
if(tr == fal || tr == fal+1 || fal == tr +1){
return true
}else return false
}
function test(arr){
let summ=0;
for (i=0; i<=arr.length; i++){
if (arr[i]==true){
summ+=1;
}
else if (arr[i]==false){
summ-=1;
}
}
if ((summ==0) || (summ==1) || (summ==-1)){
return true
}
return false
}
function test(arr)
{
let anull =0;
for(let i=0;i< arr.length;i++)
{
if(arr[i])
{
anull++;
}
}
if(anull==arr.length-anull||anull==arr.length+1-anull)
{
return true;
}
else
return false;
}
function test(arr) {
const tL = arr.filter(el => el).length;
return Math.abs(arr.length - 2*tL) <= 1;
}
function test(arr){
let anull =0;
for(let i=0;i< arr.length;i++){
if(arr[i])anull++;
}
if(anull==arr.length-anull||anull==arr.length+1-anull) return true;
else
return false;
}
function test(arr){
let dif = 0;
for (let el of arr){
if (el) {++dif} else --dif
if (Math.abs(dif) > 1) return false
}
return true
}
function count(v, a) {
return a.reduce((acc, curr) => {
if (curr === v) return acc + 1
return acc
}, 0)
}
function test(arr) {
arr = arr.map(item => !!item)
let trues = count(true, arr);
let falses = count(false, arr);
console.log(trues, falses)
if (arr.length % 2 !== 0) {
return (trues + 1 === falses) || (falses + 1 === trues)
}
return trues === falses
}
function test(arr){
let t = 0;
let f = 0;
for(let el in arr){
if(arr[el]) t++
else f++
}
return t-f == 1 || t-f == -1 || t == f
}
function test(arr){
let numberOfTrue = 0;
let numberOfFalse = 0;
for(i in arr){
if(arr[i] == true){
numberOfTrue++;
}
else{
numberOfFalse++;
}
}
if(Math.abs(numberOfFalse - numberOfTrue) <= 1){
return true;
}
else{
return false;
}
}
function test(arr) {
let fal = 0;
let tru = 0
for (let i = 0; i < arr.length; i++) {
if (arr[i] != true) fal++;
else tru++;
}
if ((tru === fal) || (tru === (fal + 1)) || (fal === (tru + 1))) {
return true }
else
return false
}
function test(arr)
{
let countTrue=0;
let countFalse=0;
for(let i=0;i< arr.length;i++){
if(arr[i]==true){
countTrue++;
}else{
countFalse++;
}
}
return Math.abs(countTrue-countFalse)>=2?false:true;
}
function test(arr){
let tcount = 0
let fcount = 0
for(let e of arr){
if(e){
tcount++
}else{
fcount++
}
}
if(Math.abs(tcount - fcount)>1){
return false
}else{
return true
}
}
function test(arr)
{
arr.sort();
let f = 0;
for(let el in arr)
{
if(arr[el] == false)
{
f++;
}
else
{
break;
}
}
let t = arr.length - f;
if(arr.length % 2 == 1)
{
if(t == f + 1 || f == t + 1)
{
return true;
}
else
{
return false;
}
}
else
{
if(t == f)
{
return true;
}
else
{
return false;
}
}
}
function test(arr) {
console.log('Антелопа')
}
function test(arr){
let t = 0;
let f = 0;
for(let i = 0; i < arr.length; i++){
if(arr[i]) t++;
else f++;
}
if(t == f || t == f+1 || t== f-1) return true;
return false;
}
function test(arr) {
console.log('Антелопа')
}
function test(arr)
{
for(let i = 0; i < arr.length - 1; i++){
if(arr[i] === arr[i - 1] || arr[i] === arr[i + 1]){
let swaped = false;
for(let j = 0; j < i; j++){
if(tryInsertBefore(arr, i, j)){
swaped = true;
break;
}
}
if (swaped){
i = 0;
continue
}
for(let j = i; j < arr.length; j++){
if(tryInsertAfter(arr, i, j)){
swaped = true;
break;
}
}
if (swaped){
i = 0;
continue
}
console.log(arr);
return false;
}
}
console.log(arr);
return true;
}
function tryInsertBefore(arr, pos, insertAfter){
console.log("tryInsertBefore");
if(arr[insertAfter] !== arr[pos] && arr[insertAfter + 1] !== arr[pos]){
arr.splice(insertAfter + 1, 0, arr[pos]);
arr.splice(pos + 1, 1)
console.log(arr)
console.log("-----")
return true;
}
return false;
}
function tryInsertAfter(arr, pos, insertAfter){
console.log("tryInsertAfter");
if(arr[insertAfter] !== arr[pos] && arr[insertAfter + 1] !== arr[pos]){
console.log(arr);
arr.splice(insertAfter + 1, 0, arr[pos]);
arr.splice(pos, 1)
console.log(arr)
console.log("-----")
return true;
}
return false;
}
function test(arr)
{
let obj = {};
let maxRepeat = 0;
for(let i of arr)
{
if(obj[i]){
obj[i]++;
}
else{
obj[i] = 1;
}
}
console.log(obj)
for(let i in obj){
if (obj[i] > maxRepeat){
maxRepeat = obj[i]
}
}
console.log(maxRepeat)
if (maxRepeat > Math.round(arr.length/2)) return 0;
return 1;
}
function test(arr){
}
let s_tr=0;
let s_fa=0;
for(let i = 0; i < arr.length;i++)
{
if(arr[i]===true)
{
s_tr++
}
if(arr[i]=== false)
{
s_fa++
}
}
if(s_tr-s_fa > 1 || s_fa - s_tr > 1)
{
return false
}
else true
}
let t=0
let f=0
for(const elem of arr){
if(elem){
t++
}else{
f++
}
}
return Math.max(t,f)<=Math.ceil(arr.length/2)
}
{
let t = 0, f = 0;
for (let el of arr) {
if (el == true) t++;
if (el == false) f++;
}
if (t-f > 1 || f-t > 1) return false;
else return true
}
let countTrue = 0;
let countFalse = 0;
arr.forEach(bool => {
if(bool == true){
countTrue++;
}else {
countFalse++;
}
});
if(countFalse == countTrue || countFalse == countTrue - 1 || countFalse == countTrue + 1){
return true;
}else {
return false;
}
}
let fcount = 0,
tcount = 0;
for (let i = 0; i < arr.length; i++){
if (arr[i]) tcount ++;
else fcount ++;
}
if (-1 <= tcount - fcount && tcount - fcount <= 1) return true;
else return false;
}
if(arr.length == 0) return false;
let t = 0, f = 0;
for(let i = 0; i < arr.length; i++){
if (arr[i]) t += 1;
else f += 1;
}
if (t == f || t - f == 1 || f - t == 1) return true;
return false;
}
let j=0
if (arr.length>1) {
for(let i=0; i< arr.length; i++){
if(arr[i]) j++
}
if((j-(arr.length-j))>=2 || ((arr.length-j)-j)>=2) {
return false
} else{
return true
}
}
}
let t = 0;
for(let v of arr) {
if(v) t += 1;
}
let l = arr.length;
return t <= (l + l%2) / 2 && t >= (l - l % 2)/2;
}
{
if (typeof x === "function") {
return('function');
}
if (Array.isArray(x)){
return 'array'
}
if (typeof x === "object"){
return 'object'
}
return 'other'
}
}
{
let a = 0
let b = 0
for(i=0; i< arr.length; i++)
{
if(arr[i]==true)
{
a++
}
else
{
b++
}
}
if(a==b||a==b+1||a==b-1)
{
return true
}
else
{
return false
}
}
const tL = arr.filter(el => el).length;
return Math.abs(arr.length - 2*tL) <= 1;
}
let tc = 0
let fc = 0
for (i = 0; i < arr.length; ++i) {
if (arr[i] == true) tc += 1
if (arr[i] == false) fc += 1
}
if (tc == fc || fc - 1 == tc || tc - 1 == fc) return true
else return false
}
let trueCount = 0;
let falseCount = 0;
for (let i = 0; i < arr.length; i++) {
if(arr[i]==true){trueCount++}
else if(arr[i]==false){falseCount++}
}
if (trueCount - falseCount >= -1 && trueCount - falseCount <= 1) {
return true
}
else return false
}
{
let countTrue = 0;
for(let i = 0; i < arr.length; i++)
{
if(arr[i] == true)
countTrue++;
}
if((2*countTrue) - arr.length >= -1 && (2*countTrue) - arr.length <= 1)
return true;
else
return false;
}
col_true = 0 ;
col_false= 0;
for (let x in arr){
if (arr[x]===true){
col_true=col_true+1
}
else{
col_false=col_false+1
}
}
}
console.log('Антелопа')
}
let true_counter = 0;
let false_counter = 0;
for(let each of arr){
if(each == true){
true_counter++;
}else{
false_counter++;
}
}
if(true_counter - false_counter == 1 || true_counter - false_counter == -1 || true_counter == false_counter){
return true;
}else{
return false;
}
}
let a = 0;
let b = 0;
for (let i = 0; i< arr.length; i ++){
if (arr[i] == true){
a++;
}
else{
b++;
}
}
if (a - 1 > b || b - 1 > a){
return false;
}
else {
return true ;
}
}
{
let c1 = 0
let c2 = 0
for (let i = 0;i < arr.length;i++)
{
arr[i] && c1++
}
for (i = 0; i < arr.length;i++)
{
arr[i] || c2++
}
let t = c1 === c2 || c1-c2 === 1 || c1-c2 === -1
return t
}
console.log('pika')
}
let n = 0;
let m = 0;
for(let i = 0; i < arr.length; i++){
if(arr[i] == true){
++n;
}else{
++m;
}
}
let result = (n == m || n == m + 1) ? true : false;
return result;
}
console.log('bebra')
}
let t = 0;
let f = 0;
for(let i = 0; i < arr.length; i++){
if (arr[i] == true)
t++;
else
f++;
}
if (t - f == 1 || t - f == -1 || t - f == 0)
return true;
else
return false;
}
let tr = 0, fl = 0;
for (let i = 0; i < arr.length; i++) {
if (Boolean(arr[i]) === true)
tr++;
else
fl++;
}
if (tr > (fl+1) || fl > (tr+1))
return false;
else
return true;
}
let sumTrue = 0;
let sumFalse = 0;
for (let i = 0; i < arr.length; i++) {
if (arr[i] === true) {
sumTrue ++;
} else {sumFalse ++;}
}
if ((sumTrue % 2 != 0) && (sumFalse % 2 == 0) || (sumTrue % 2 == 0) && (sumFalse % 2 != 0)) {
return true;
} else if ((sumTrue % 2 == 0.5) && (sumFalse % 2 == 0.5)) {
return false;
}
}
let diff = arr.length - 2 * arr.filter(a => a).length;
return diff <= 1 && diff >= -1;
}
let anull =0;
for(let i=0;i< arr.length;i++){
if(arr[i] == true){
anull++;
}
}
if(anull==arr.length-anull||anull==arr.length+1-anull){
return true;
}
else {
return false;
}
}
console.log('sanya eto bober')
}
let a = 0
let b = 0;
for(let i = 0; i < arr.length; i++) {
if ( arr [ i ] ) {
a++;
}
else
b++;
}
return a == b || a == b + 1 || a == b - 1;
}
let a = 0
let b = 0;
for(let i = 0; i < arr.length; i++) {
if ( arr [ i ] ) {
a++;
}
else
b++;
}
return a == b || a == b + 1 || a == b - 1;
}
let count1 = 0
let count2 = 0
for (let i = 0; i< arr.length; i++){
if (arr[i]==true){
count1 ++
}
else{count2++}
}
if (count1==count2){
if (count1-count2 < 2){
return true
}
}
if (count1>count2){
if (count1-count2 < 2){
return true
}
}
if (count2>count1){
if (count2-count1 < 2){
return true
}
}
return false
}
const test = arr => arr.every((val, i) => val !== arr[i+1]);
}
let counter = array.length;
// пока есть елементы
while (counter > 0) {
// выбрать случайный индекс
let index = Math.floor(Math.random() * counter);
// уменьшить счетчик на 1
counter--;
// и поменять последний елемент
let temp = array[counter];
array[counter] = array[index];
array[index] = temp;
}
return array;
}
let obj = {};
let maxRepeat = 0;
for(let i of arr){
if(obj[i]){
obj[i]++;
}
else{
obj[i] = 1;
}
}
console.log(obj)
for(let i in obj){
if (obj[i] > maxRepeat){
maxRepeat = obj[i]
}
}
console.log(maxRepeat)
if (maxRepeat > Math.round(arr.length/2)) return false;
return true;
}
{
let f=0, t=0
for(let i = arr.length-1; i>=0;i--)
if(arr[i]==1)
t++
else f++
return Math.abs(t-f)< 2
}
let numbersOfTrue = 0;
let numbersOfFalse = 0;
for(i = 0; i < arr.length; i++) {
if (arr[i] == true) {
numbersOfTrue++;
} else if (arr[i] == false) {
numbersOfFalse++;
}
}
if(numbersOfTrue == numbersOfFalse || numbersOfTrue - 1 == numbersOfFalse || numbersOfTrue + 1 == numbersOfFalse) {
return true;
} else {
return false;
}
}
}
let t = 0, f = 0;
for (let i of arr){
console.log(i)
if (i == 1) t++;
if (i == 0) f++;
}
if (Math.abs(t-f) >=0 && Math.abs(t-f) <= 1) return true;
else return false;
}
{
arr.sort();
let f=0;
for(let el in arr)
if(arr[el]==false)
f++
else
break;
let t = arr.length-f;
if(arr.length%2==1){
if(t==f+1 || f==t+1)
return true;
else
return false;
}
else{
if(t==f)
return true;
else
return false;
}
}
console.log("Denis")
}
}
let b=0;
for(i=0;i< arr.length;i++){
let t=1
for(j=i+1;j< arr.length;j++){
if(arr[i]==arr[j]) t++
}
b=Math.max(b,t)
}
if(b<(arr.length/2)+1){
return true
}
return false
}
let count1 = 0;
let count2 = 0;
for( let i = 0; i < arr.length; i++){
if(arr[i] == true){
count1++;
}
if(arr[i] == false){
count2++;
}
}
if(count1 == count2){
return true;
}
if(count1 == count2 + 1 || count2 == count1 + 1){
return true;
}
else{
return false;
};
}
let countT = arr.filter(x=>x==true).length
let countF = arr.filter(x=>x==false).length
return console.log(countF,countT)
if(countF==countT || countF-countT==1|| countT-countF==1){
return true
}
return false
}
{
let counterTrue = 0;
let counterFalse = 0;
for(i = 0; i < arr.length; i++)
{
if(arr[i] == true)
{
counterTrue += 1;
}
if(arr[i] == false)
{
counterFalse += 1;
}
}
if(counterFalse == counterTrue-1 || counterTrue == counterFalse-1 || counterFalse == counterTrue)
{
return true;
}
else
{
return false;
}
}
{
let trueN = 0;
let falseN = 0;
for(let i = 0;i< arr.length;i++)
{
if(arr[i] == false) falseN++;
else trueN++
}
if(Math.abs(trueN-falseN)>1) return false;
return true;
}
{
let counterTR=0;
let counterFal=0;
for(let i =0; i
counterTR+=1
}
else if(arr[i]== false){
counterFal+=1
}
}
if(counterTR-counterFal==1 || counterFal-counterTR==1 || counterFal-counterTR==0){
return true
}else{
return false
}
}
{
let pos = 0;
let neg = 0;
for(let i = 0; i < arr.length; i++){
if(arr[i]){
pos++;
}else {
neg++;
}
}
return pos == neg || pos == neg +1 || pos == neg-1;
}
}
{
let counter = 0;
for (let i = 0; i < arr.length; i++)
{
if (arr[i] == true)
counter++;
else if (arr[i] == false)
counter--;
}
if (counter == 0 || counter == -1 || counter == 1)
return 1;
return 0;
}
a=0;
b=0;
for (let i=0; i< arr.length; i++)
{
if(arr[i]==true)
a++;
else
b++;
}
return a==b-1 || a==b || a==b+1;
}
let new_array = {};
for(let i = 0; i < arr.length; i++){
let el = arr[i];
if (new_array[el] != undefined){
new_array[el]++;
}
else{
new_array[el] = 1
}
}
let arr_el = Object.values(new_array)
for(let count = 0; count < arr_el.length; count++){
let g = count + 1;
if((arr_el[count] == arr_el[g])||(arr_el[count] - 1 == arr_el[g])||(arr_el[count] == arr_el[g] - 1)){
return true
}
else{
return false
}
}
}
console.log('Антелопа')
}
console.log('Kyky')
}
console.log('Антелопа')
}
let sum1 = 0;
for (let e of arr ) {
if (e) sum1 ++;
else sum1 --;
}
return Math.abs(sum1)<= 1;
}
console.log('Антелопа')
}
let ifTrue = true;
let truecounter = 0;
let falsecounter = 0;
for (let i = 0; i< arr.length; i++){
if(arr[i]){truecounter++}
else{falsecounter++}
}
if ((truecounter-falsecounter)>1 || (falsecounter-truecounter)>1){ifTrue=false}
return ifTrue
}
let t = 0;
let f = 0;
for (let i = 0; i < arr.length; i++) {
if (arr[i] == true) t++;
else f++;
}
if (Math.abs(t-f) < 2) return true;
else return false;
}
let countTrue = 0
let countFalse = 0
for (let i = 0; i < arr.length; i++){
if (arr[i] == true)
countTrue++
else
countFalse++
}
if (countTrue - countFalse >= 2 || countFalse - countTrue >= 2)
return false
else
return true
}
let countTrue = 0;
let countFalse = 0;
for (let i = 0; i < arr.length; i++)
if (arr[i]) countTrue++;
else countFalse++;
return Math.abs(countTrue - countFalse) <= 1;
}
let i = 0
for (let element of arr) {
if (element == true) i++
}
return Math.ceil(arr.length / 2) == i
}
let nt = 0;
for (let value of arr){
if (value == true) nt++;
}
return (arr.length - 2*nt >= -1 && arr.length - 2*nt <= 1);
}
{
let t = 0;
for(let i = 0; i
t++;
}
}
return Math.abs(arr.length-2*t)<=1;
}
let T = 0, F = 0;
for(let i = 0; i < arr.length; i++)
{
if(arr[i])
T++;
else
F++;
}
if(module(T - F) < 2)
return true;
return false;
}
function module(num)
{
if(num < 0)
num *= -1;
return num;
}
result = arr.reduce((acc, value) => acc = (value)? acc+1 : acc-1 , 0)
return (result <= 1 && result >= -1)? true:false;
}
if (Array.isArray(x) == true) {
return 'array'
}
if (typeof (x) == 'function') {
return 'function'
}
if (typeof (x) == 'object') {
return 'object'
}
else {
return 'other'
}
}
trueCount = 0;
falseCount = 0;
arr.forEach(el=>{if(el == true){trueCount++}else{falseCount++}});
if(trueCount === falseCount || trueCount === falseCount+1 || trueCount+1 === falseCount){
return true;
}
return false;
}
let a = 0
let b = 0;
for(let i = 0; i < arr.length; i++) {
if (arr[i]) {
a++;
}
else {
b++;
}
}
return a == b || a == b+1 || a == b-1;
}
{
}
let count_true=0;
let count_false=0;
for (let i = 0; i< arr.length; i++){
if(arr[i]==true){
count_true+=1
}
else if(arr[i]==false){
count_false+=1
}
}
if(count_false==0 || count_true==0){
return false
}
else if(arr.length==3){
return true
}
else if((Math.max(count_true, count_false)/Math.min(count_true, count_false))< 2){
return true
}
else{
return false
}
}
let t=0,f=0;
for(let i =0;i< arr.length;i++){
if(arr[i]==false){f++;}
else if(arr[i]==true){t++;}
}
if(t==f||t-1==f||t+1==f){return true;}
else{return false}
}
let a = 0, b = 0;
for(let i = 0; i < arr.length; i++) {
if (arr[i]) a++;
else b++;
}
return a == b || a == b+1 || a == b-1;
}
let c = {};
for(e of arr) {
if(!(e in c))
c[e] = 0
c[e]++;
}
let val = Object.values(c);
if(val.includes(0))
return false;
else if(arr.length == 3)
return true;
return Math.max(...val)/Math.min(...val) < 2;
}
tr = arr.filter(x => x==true).length
fal = arr.filter(x => x==false).length
if(tr == fal || tr == fal+1 || fal == tr +1){
return true
}else return false
}
let summ=0;
for (i=0; i<=arr.length; i++){
if (arr[i]==true){
summ+=1;
}
else if (arr[i]==false){
summ-=1;
}
}
if ((summ==0) || (summ==1) || (summ==-1)){
return true
}
return false
}
{
let anull =0;
for(let i=0;i< arr.length;i++)
{
if(arr[i])
{
anull++;
}
}
if(anull==arr.length-anull||anull==arr.length+1-anull)
{
return true;
}
else
return false;
}
const tL = arr.filter(el => el).length;
return Math.abs(arr.length - 2*tL) <= 1;
}
let anull =0;
for(let i=0;i< arr.length;i++){
if(arr[i])anull++;
}
if(anull==arr.length-anull||anull==arr.length+1-anull) return true;
else
return false;
}
let dif = 0;
for (let el of arr){
if (el) {++dif} else --dif
if (Math.abs(dif) > 1) return false
}
return true
}
return a.reduce((acc, curr) => {
if (curr === v) return acc + 1
return acc
}, 0)
}
function test(arr) {
arr = arr.map(item => !!item)
let trues = count(true, arr);
let falses = count(false, arr);
console.log(trues, falses)
if (arr.length % 2 !== 0) {
return (trues + 1 === falses) || (falses + 1 === trues)
}
return trues === falses
}
let t = 0;
let f = 0;
for(let el in arr){
if(arr[el]) t++
else f++
}
return t-f == 1 || t-f == -1 || t == f
}
let numberOfTrue = 0;
let numberOfFalse = 0;
for(i in arr){
if(arr[i] == true){
numberOfTrue++;
}
else{
numberOfFalse++;
}
}
if(Math.abs(numberOfFalse - numberOfTrue) <= 1){
return true;
}
else{
return false;
}
}
let fal = 0;
let tru = 0
for (let i = 0; i < arr.length; i++) {
if (arr[i] != true) fal++;
else tru++;
}
if ((tru === fal) || (tru === (fal + 1)) || (fal === (tru + 1))) {
return true }
else
return false
}
{
let countTrue=0;
let countFalse=0;
for(let i=0;i< arr.length;i++){
if(arr[i]==true){
countTrue++;
}else{
countFalse++;
}
}
return Math.abs(countTrue-countFalse)>=2?false:true;
}
let tcount = 0
let fcount = 0
for(let e of arr){
if(e){
tcount++
}else{
fcount++
}
}
if(Math.abs(tcount - fcount)>1){
return false
}else{
return true
}
}
{
arr.sort();
let f = 0;
for(let el in arr)
{
if(arr[el] == false)
{
f++;
}
else
{
break;
}
}
let t = arr.length - f;
if(arr.length % 2 == 1)
{
if(t == f + 1 || f == t + 1)
{
return true;
}
else
{
return false;
}
}
else
{
if(t == f)
{
return true;
}
else
{
return false;
}
}
}
console.log('Антелопа')
}
let t = 0;
let f = 0;
for(let i = 0; i < arr.length; i++){
if(arr[i]) t++;
else f++;
}
if(t == f || t == f+1 || t== f-1) return true;
return false;
}
console.log('Антелопа')
}
{
for(let i = 0; i < arr.length - 1; i++){
if(arr[i] === arr[i - 1] || arr[i] === arr[i + 1]){
let swaped = false;
for(let j = 0; j < i; j++){
if(tryInsertBefore(arr, i, j)){
swaped = true;
break;
}
}
if (swaped){
i = 0;
continue
}
for(let j = i; j < arr.length; j++){
if(tryInsertAfter(arr, i, j)){
swaped = true;
break;
}
}
if (swaped){
i = 0;
continue
}
console.log(arr);
return false;
}
}
console.log(arr);
return true;
}
function tryInsertBefore(arr, pos, insertAfter){
console.log("tryInsertBefore");
if(arr[insertAfter] !== arr[pos] && arr[insertAfter + 1] !== arr[pos]){
arr.splice(insertAfter + 1, 0, arr[pos]);
arr.splice(pos + 1, 1)
console.log(arr)
console.log("-----")
return true;
}
return false;
}
function tryInsertAfter(arr, pos, insertAfter){
console.log("tryInsertAfter");
if(arr[insertAfter] !== arr[pos] && arr[insertAfter + 1] !== arr[pos]){
console.log(arr);
arr.splice(insertAfter + 1, 0, arr[pos]);
arr.splice(pos, 1)
console.log(arr)
console.log("-----")
return true;
}
return false;
}
{
let obj = {};
let maxRepeat = 0;
for(let i of arr)
{
if(obj[i]){
obj[i]++;
}
else{
obj[i] = 1;
}
}
console.log(obj)
for(let i in obj){
if (obj[i] > maxRepeat){
maxRepeat = obj[i]
}
}
console.log(maxRepeat)
if (maxRepeat > Math.round(arr.length/2)) return 0;
return 1;
}
}