Fivestars Interview Question

Write a function that takes any number of parameters and add them together. Example: 1, "2", 10.4 Example: "Bob", 5, "Ten" Example: no parameters

Interview Answer

Anonymous

Feb 18, 2022

I began by attempting to write a function that takes variadic parameters, but the interviewer steered me away from this. He said that it would be unnecessary. Eventually, he said that the parameter should be of type "Any", which would cover multiple parameters or nil. Next I tried to cast the parameters into an integer, assuming the strings would fail. Instead, he advised me to cast them to a string first, then an integer. The code became a garbled mess and that is when he cut me off. No amount of Leetcode problems will prepare you for this interview.