# CS1101S (T08H): Studio 2
17 August 2021 .
## Source Academy Burger Joint
Suppose we’re designing a point-of-sale and order-tracking system for a new burger joint. It is a small joint and it only sells 4 options for combos: Classic Single Combo (hamburger with one patty), Classic Double With Cheese Combo (2 patties), and Classic Triple with Cheese Combo (3 patties), Avant-Garde Quadruple with Guacamole Combo (4 patties). We shall encode these combos as 1, 2, 3, and 4 respectively. Each meal can be biggie-sized to acquire a larger box of fries and drink. A biggie-sized combo is represented by 5, 6, 7, and 8 respectively, for combos 1, 2, 3, and 4 respectively.
### Question 1
Write a function named `biggie_size` which when given a regular combo returns a _biggie-sized_ version.
```javascript
function biggie_size(x){
return x+4;
}
```
### Question 2
Write a function named `unbiggie_size` which when given a biggie-sized combo returns a _non-biggie-sized_ version.
```javascript
// YOUR CODE HERE
function unbiggie_size(x){
return x-4;
}
```
### Question 3
Write a function named `is_biggie_size` which when given a combo, returns `true` if the combo has been _biggie-sized_ and `false` otherwise.
```javascript
function is_biggie_size(n){
return n > 4;
}
```
### Question 4
Write a function named `combo_price` which takes a combo and returns the price of the combo. Each patty costs $1.17, and a _biggie-sized_ version costs $0.50 extra overall.
```javascript
// YOUR CODE HERE
function combo_price(combo) {
const base_combo = combo > 4 ? combo - 4 : combo;
return combo > 4 ? base_combo * 1.17 + 0.5 : base_combo * 1.17;
}
function combo_price(meal) {
return is_biggie_size(meal)
? 0.50 + (1.17 * unbiggie_size(meal))
: 1.17 * meal;
}
```
### Question 5
An order is a collection of combos. We will encode an order as each digit representing a combo. For example, the order 237 represents a Double, Triple, and _biggie-sized_ Triple.
Write a function named `empty_order` which takes no arguments and returns an empty order which is represented by 0.
```javascript
function empty_order() {
return 0;
}
```
### Question 6
Write a function named `add_to_order` which takes an order and a combo and returns a new order which contains the contents of the old order and the new combo. For example, `add_to_order(1, 2)` returns `12`.
```javascript
function add_to_order(order, combo){
return stringify(order) + stringify(combo);
}
function add_to_order(order, combo) {
return order*10+combo;
}
```
### Question 7
Write a function named `last_combo` which takes an order and returns the last combo. For example, `last_combo(321)` returns `1`.
```javascript
function last_combo(order) {
return order % 10;
}
```
### Question 8
Write a function named `other_combos` which takes an order and returns a new order without the last combo. For example, `other_combos(321)` returns `32`.
```javascript
// YOUR CODE HERE
function other_combos(order) {
const new_order = order / 10;
return math_floor(new_order);
}
function other_combos(order) {
return (order - (order % 10)) / 10;
}
```
### Get leftmost n digits
Write a function named `get_leftmost_n` which takes a number and an integer n and returns a new order with just the first n combos. For example, `get_leftmost_n(321321, 4)` returns `3213`.
```javascript
function get_leftmost_n(number, n) {
const num_digits = math_floor(math_log10(number)) + 1;
return math_floor(number / math_pow(10, (num_digits - n)));
}
```
### Adding a digit to the front of a number
Write a function named `add_digit_to_front` which takes a digit and a number and returns a new number with the digit in front. For example, `add_digit_to_front(9, 4444)` returns `94444`.
```javascript
function add_digit_to_front(n,num){
const num_digits = math_floor(math_log10(num)) + 1;
const new_num = n * math_pow(10,num_digits) + num;
return new_num;
}
function add_digit_to_front(digit, number) {
const num_digits = math_ceil(math_log10(number + 1));
return digit * math_pow(10, num_digits) + number;
}
add_digit_to_front(9,4444);
```
math_log10()
math_pow(digit, power)