Решения от подписчиков - JavaScript Задачи #2

Решения от подписчиков - JavaScript Задачи #2


@drgrh

let money = parseInt(prompt('Это ограбление, собака, давай нам свои деньги:'));
let fst, snd, thd, temp;
let arr = [];

if (!Number(money) || money === 0) {
 console.log('Не пытайся нас нае*ать!');
} else {
 if (money % 3 !== 0) {
   temp = Math.floor(money / 3)
   fst = temp - 1;
   snd = temp;
   thd = money - (fst + snd);
 } else if (money % 3 === 0) {
   fst = money / 3 - 1;
   snd = money / 3;
   thd = money / 3 + 1;
 } 
 arr.push(fst, snd, thd);
 console.log(arr);
}

Олег Геннадьевич (без никнейма)

function test(n){
 var arr=[] ;
arr[1]=Math.floor(n/3) ;
arr[0]=arr[1]-1;
arr[2]=n-(arr[0]+arr[1]);
if(n>=0&&n<3){
 arr[0]=0;
 arr[1]=0;
 arr[2]=n;
}
 return arr;
 }
 console. log(test(7)) ;

@danil39801

function input(num) {
 if((num % 3) == 0) {
   console.log([num / 3 - 1, num / 3, num / 3 + 1]);
 } else {
   console.log([Math.floor(num / 3)-1,Math.floor(num / 3), num - (Number(Math.floor(num / 3 - 1))+Number(Math.floor(num / 3)))]);
 }
}

input(8);

@phantomhere

let a = prompt('give me money son');
       let first, second, third;
       let arr = [];
       if (a % 3 == 0) {
           second = a / 3;
           third = second - 1;
           first = +second + 1;
           arr.push(third, second, first);
       }
       else {
           second = Math.floor(a / 3);
           third = second - 1;
           first = a - second - third;
           arr.push(third, second, first);
       }

       console.log(arr);

Report Page