./studio_2.sh

x_combo

Implement a function to get a specific order from the combo. Let’s call this function x_combo where x refers to the position of a order from the back of a combo.

  1. x is one-indexed

  2. Assume that all inputs are valid - x will never be more than the number of digits in combo

function x_order(order, x) {
    // YOUR SOLUTION HERE 
}

// Examples
x_order(1234, 1) // 4
x_order(1234, 3) // 2
x_order(12345678, 8) // 1x_combo
Solution
function last_combo(order) {
    // Question 7 in Studio 2 Worksheet
    return order % 10;
}

function x_order(order, x) {
    return last_combo(math_floor(order / math_pow(10, x-1)));
}

Last updated