Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cake(input) {
- index = 0;
- let width = Number(input[index]);
- index++;
- let length = Number(input[index]);
- index++;
- let cakePieces = width * length;
- while (cakePieces > 0) {
- let command = input[index];
- index++;
- if (command === "STOP") {
- console.log(`${cakePieces} pieces are left.`);
- break;
- }
- cakePieces -= Number([command]);
- }
- if (cakePieces <= 0) {
- let diff = Math.abs(cakePieces);
- console.log(`No more cake left! You need ${diff} pieces more.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment