You need Login/Signup to run/submit the code.
Implement Tuple Function | LinkedIn Frontend Interview Question | JavaScript Problem Solving
@Devtools Tech
In this question, you need to implement a tuple
function that takes a string
as input and converts it into a array of arrays
. The tuple
should support a function multiply
that multiples ith
item of each nested array.
Syntax
const item = tuple(input);
item.multiply(position);
Arguments
input (String)
: the string that we need to convert
Returns
An array
Example
const input = `(1, 2, 3) , (4, 5, 6) , (7, 8, 9)`;
// Convert it into
// [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
const item = tuple(input);
// Multiples 2nd item in each nested array
// i.e. 2 * 5 * 8 = 80
console.log(item.multiply(2));
The method multiply
should exist on the return value of the tuple
function. You can either directly set it on the return value or on the Array prototype.
Submission
Start the timer, complete your solution, test your solution against the test cases provided by the platform, and submit it. Ideally, you should finish this question within 30 mins.