Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- РЕШЕНИЕ С FOR:
- function bitcoin(input) {
- let sum = 0;
- let firstBuy = 0;
- for (let i = 1; i <= input.length; i++) {
- let currentSum = input[i - 1] * 67.51;
- if (i % 3 === 0) {
- currentSum *= 0.7;
- }
- sum += currentSum;
- if (firstBuy === 0 && sum >= 11949.16) {
- firstBuy = i;
- }
- }
- let bitcoins = Math.floor(sum / 11949.16);
- sum %= 11949.16;
- console.log(`Bought bitcoins: ${bitcoins}`);
- if (bitcoins !== 0) {
- console.log(`Day of the first purchased bitcoin: ${firstBuy}`);
- }
- console.log(`Left money: ${sum.toFixed(2)} lv.`);
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- function bitcoin(input) {
- let sum = 0;
- let firstBuy = 0;
- for (let i = 1; i <= input.length; i++) {
- sum += input[i - 1] * 67.51 * (i % 3 === 0 ? 0.7 : 1);
- firstBuy += firstBuy === 0 && sum >= 11949.16 ? i : 0;
- }
- console.log(`Bought bitcoins: ${parseInt(sum / 11949.16)}\n${parseInt(sum / 11949.16) !== 0 ?
- `Day of the first purchased bitcoin: ${firstBuy}\n` : ''}Left money: ${(sum % 11949.16).toFixed(2)} lv.`);
- }
- РЕШЕНИЕ С WHILE, SHIFT() И ТЕРНАРЕН ОПЕРАТОР:
- function bitcoin(input) {
- let sum = 0;
- let firstBuy = 0;
- let i = 1;
- while (input.length !== 0) {
- sum += input.shift() * 67.51 * (i % 3 === 0 ? 0.7 : 1);
- firstBuy += firstBuy === 0 && sum >= 11949.16 ? i : 0;
- i++;
- }
- console.log(`Bought bitcoins: ${parseInt(sum / 11949.16)}\n${parseInt(sum / 11949.16) !== 0 ?
- `Day of the first purchased bitcoin: ${firstBuy}\n` : ''}Left money: ${(sum % 11949.16).toFixed(2)} lv.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement