First Orion Interview Question for SDE1s
- 0of 0 votes
AnswerWrite a function that takes a string of javascript code as parameter and returns a new string with these literals standardized on double quotes.
- MM July 07, 2016 in United States
For example if the input is
/* This method says 'hello'*/
function sayHello()
{alert('hello')}
The out put should be
/* This method says 'hello'*/
function sayHello()
{alert("hello")}
The quoted text in the code section of the function should be changed to double quotes. The quotes used in the comments section should be left alone.
static string standardizeJavaScript(string inputJavaScript)
{
string temp = string.Empty;
if (string.IsNullOrEmpty(inputJavaScript))
return inputJavaScript;
bool updateQuote = false;
string output = string.Empty;
string[] split = inputJavaScript.Split('\n');
for (int i = 0; i < split.Length; i++)
{
if (split[i].Contains("{"))
updateQuote = true;
//if (split[i].Contains("{"))
// updateQuote = false;
if (updateQuote)
{
split[i] = split[i].Replace("'", "\"");
output = output +"\n" + (split[i]);
}
}
return output;
}| Report Duplicate | Flag | PURGE
First Orion SDE1
Interview Type: Written Test
- seneza.gaston@philander.edu February 14, 2020