Skip to content

Instantly share code, notes, and snippets.

@sibnerian
Created February 7, 2019 17:31
Show Gist options
  • Save sibnerian/1128c4e99ce5137437e2fd58c285e42e to your computer and use it in GitHub Desktop.
Save sibnerian/1128c4e99ce5137437e2fd58c285e42e to your computer and use it in GitHub Desktop.
[
{
"answer": "pure",
"choices": ["impure", "pure"],
"function": "const sums = (a,b) => {return a+b}",
"question": "Is the following function pure or impure?"
},
{
"answer": "O(b)",
"choices": ["O(a + b)", "O(ab)", "O(a)", "O(b)"],
"function": "const func = (a, b) => { \n let result = 0;\n for(let i = 0; i < b, i++){ \n result += a; \n }\n return result;\n}",
"question": "What is the time complexity of the following function?"
},
{
"answer": "Merge Sort",
"choices": ["Bubble Sort", "Merge Sort", "Insertion Sort", "Quick Sort"],
"question": "Which of these sorting algorithms is fastest for Worst Case?"
},
{
"answer": "O(n!)",
"choices": ["O(n^2)", "O(2^n)", "O(n!)", "O(log(n))"],
"question": "Which of these time complexities is slowest?"
},
{
"answer": "O(1)",
"choices": ["O(n)", "O(log(n))", "O(1)", "O(n^2)"],
"function": "const func = (arr, elem) => {\n for(let i = 0; i < arr.length; i++){\n if(arr[i] == elem) return true; \n }\n return false;\n}",
"question": "What is the Best Case time complexity for the following function?"
},
{
"answer": "O(n)",
"choices": ["O(n)", "O(log(n))", "O(1)", "O(n^2)"],
"function": "const func = (arr, elem) => {\n for(let i = 0; i < arr.length; i++){\n if(arr[i] == elem) return true; \n }\n return false;\n}",
"question": "What is the Worst Case time complexity for the following function?"
},
{
"answer": "O(1)",
"choices": ["O(1)", "O(a)", "O(b)"],
"function": "const func = (a, b) => {\nfor (let i = 0; i < 100000000, i++){\na+= b;\n}\nreturn a;\n}",
"question": "What is the time complexity for the following function?"
},
{
"answer": "none of the above",
"choices": ["12", "0", "7", "none of the above"],
"function": "function getRectArea(3, 4) {\n if (width > 0 && height > 0) {\n return;\n }\n}",
"question": "What is the expected output of the following function?"
},
{
"answer": "O(1)",
"choices": ["O(1)", "O(n)", "O(n^2)", "O(n!)"],
"question": "What is the look up time in a hash table?"
},
{
"answer": "O(n^2), O(2^n), O(n!)",
"choices": [
"O(n^2), O(n log n), O(n!)",
"O(n), O(n log n), O(1)",
"O(n^2), O(2^n), O(n!)",
"O(1), O(n^2), O(log n)"
],
"question": "Which list is ordered from fastest to slowest?"
},
{
"answer": "120",
"choices": ["120", "0", "720", "6"],
"function": "const factorial = number => {\n return number < 2 ? 1 : number * factorial(number - 1);\n};\n\nfactorial(5)",
"question": "What is the expected output of the following function?"
},
{
"answer": "<script>",
"choices": ["<scripting>", "<js>", "<script>", "<javascript>"],
"question": "Into which HTML element do we put JavaScript we want to execute?"
},
{
"answer": "document.getElementById(\"demo\").innerHTML = \"Hello World!\";",
"choices": [
"document.getElementById(\"demo\").innerHTML = \"Hello World!\";",
"document.getElementByName(\"p\").innerHTML = \"Hello World!\";",
"#demo.innerHTML = \"Hello World!\";",
"document.getElement(\"p\").innerHTML = \"Hello World!\";"
],
"function": "<p id=\"demo\">This is a demonstration.</p>",
"question": "What is the correct JavaScript syntax to change the content of a HTML element?"
},
{
"answer": "function myFunction() {}",
"choices": [
"myFunction = function()",
"function:myFunction() {}",
"function myFunction() {}"
],
"question": "How do you create a function called myFunction in JavaScript?"
},
{
"answer": "8",
"choices": ["8", "0", "9", "error"],
"function": "<script type=\"text/javascript\"> \n var a=\"GeeksforGeeks\"; \n var x=a.lastIndexOf(\"G\"); \n document.write(x); \n</script>",
"question": "Predict the output of the following"
},
{
"answer": "program",
"choices": ["interface", "throws", "program", "short"],
"question": "Which of the following is not a reserved word in JavaScript?"
},
{
"answer": "s",
"choices": ["sf", "ks", "s", "k"],
"function": "<script type=\"text/javascript\" language=\"javascript\"> \n \n var a = \"GeeksforGeeks\"; \n var result = a.substring(4, 5); \n document.write(result); \n \n</script>",
"question": "Predict the output of the following"
},
{
"answer": "isInteger(value)",
"choices": [
"Integer(value)",
"ifInteger(value)",
"isInteger(value)",
"ifinteger(value)"
],
"question": "In JavaScript, we do not have datatypes like integer and float. What is the function that can be used to check if the number is an integer or not?"
},
{
"answer": "[2,1,1]",
"choices": ["[2,1,1]", "[2,undefined,1]", "[2,1,2]", "[2,undefined,2]"],
"function": "(function(x, f = () => x) {\n var x;\n var y = x;\n x = 2;\n return [x, y, f()];\n})(1)",
"question": "Predict the output of the following"
},
{
"answer": "['outer', 'outer']",
"choices": [
"['inner', 'outer']",
"['outer', 'outer']",
"[undefined, undefined]",
"Error"
],
"function": "(function() {\n return [\n (() => this.x).bind({ x: 'inner' })(),\n (() => this.x)()\n ]\n}).call({ x: 'outer' });",
"question": "Predict the output of the following"
},
{
"answer": "['function', 'undefined']",
"choices": [
"['function', 'undefined']",
"['function', 'function']",
"['undefined', 'undefined']",
"Error"
],
"function": "(function() {\n let f = this ? class g { } : class h { };\n return [\n typeof f,\n typeof h\n ];\n})();",
"question": "Predict the output of the following"
},
{
"answer": "object",
"choices": ["function", "object", "undefined", "Error"],
"function": "(typeof (new (class { class () {} })))",
"question": "What is the output of the following?"
},
{
"answer": "Error",
"choices": ["1", "3", "[1,2,3]", "Error"],
"function": "((...x, xs)=>x)(1,2,3)",
"question": "What is the output of the following?"
},
{
"answer": "//This is a comment",
"choices": [
"<!–This is a comment–&gt",
"//This is a comment",
"–This is a comment",
"**This is a comment**"
],
"question": "What is the correct syntax for adding comments in JavaScript?"
},
{
"answer": "number",
"choices": ["float", "number", "integer", "double"],
"function": "document.write(typeof(24.49));",
"question": "What will be the output of the following"
},
{
"answer": "forEach()",
"choices": ["forEach()", "every()", "forEvery()", "each()"],
"question": "Which of the following calls a function for each element in the array?"
},
{
"answer": "Both of the above",
"choices": [
"You should not use any of the JavaScript reserved keyword as variable name.",
"JavaScript variable names should not start with a numeral (0-9)",
"Both of the above",
"None of the above"
],
"question": "Which of the following is true about variable naming conventions in JavaScript?"
},
{
"answer": "document.cookie = 'key1 = value1; key2 = value2; expires = date';",
"choices": [
"document.cookie = 'key1 = value1; key2 = value2; expires = date';",
"browser.cookie = 'key1 = value1; key2 = value2; expires = date';",
"window.cookie = 'key1 = value1; key2 = value2; expires = date';",
"navigator.cookie = 'key1 = value1; key2 = value2; expires = date';"
],
"question": "Which of the following is the correct syntax to create a cookie using JavaScript?"
},
{
"answer": "indexOf()",
"choices": ["getIndex()", "location()", "indexOf()", "None of the above"],
"question": "Which built-in method returns the index of the first occurance within a string?"
},
{
"answer": "toExponential()",
"choices": ["toExponential()", "location()", "indexOf()", "toFixed()"],
"question": "Which of the following function forces a number to display in exponential notation?"
},
{
"answer": "replace()",
"choices": ["concat()", "match()", "replace()", "search()"],
"question": "Which of the following function is used to find a match between a regular expression and a string, and replaces the matched substring with a new substring?"
},
{
"answer": "true",
"choices": ["true", "false", "0", "error"],
"function": "var foo = function foo() {\n console.log(foo === foo); \n};\nfoo();",
"question": "What is printed in the console?"
},
{
"answer": "false",
"choices": ["true", "false", "NaN", "typeError"],
"function": "(true + false) > 2 + true;",
"question": "What is the result?"
},
{
"answer": "2",
"choices": ["0", "2", "11", "\"11\""],
"function": "\"1\" - - \"1\";",
"question": "What is the result?"
},
{
"answer": "3,1",
"choices": ["1,2", "1,3", "2,1", "2,3", "3,1", "3,2"],
"function": "var x = 3;\n\nvar foo = {\n x: 2,\n baz: {\n x: 1,\n bar: function() {\n return this.x;\n }\n }\n}\n\nvar go = foo.baz.bar;\n\nalert(go());\nalert(foo.baz.bar());",
"question": "What is the order of values alerted?"
},
{
"answer": "f, o, o",
"choices": [
"f, o, o",
"TypeError",
"['f', 'o', 'o']",
"[][]['f', 'o', 'o']"
],
"function": "[] + [] + 'foo'.split('');",
"question": "What is the result?"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment