Ready Monetized Wordpress Website

EARN MONEY FREELANCING

Tuesday, August 13, 2019

JavaScript Interview Questions

I recently had an interview for a Full Stack position and these were the questions. I had 20 min to finish it but it took melike 30, anyways, I didn't get it as I only got 2 questions right :sad face:

  1. Correct the implementation of JavaScript function below assuming that the documentation is correct. Use a highlighter to identify your corrections.

/** Maps items from an array using a function.

* @arg {array} array Array to map.

* @arg {function(item,index)} fun Function to call for each item. The return value is appended to the output array, unless undefined.

* @arg {array} [out] Optional output array.

* @ret {array} The output array. */

function map(array, fun, out) {

var n = array.length,

m = out.length,

i;

if (out === null)

out = []

for (i = 0; i <= n; ++i)

v = array[i];

v = fun(v, i);

if (v !== undefined) {

out[++m] = v;

}

}

  1. Assuming the implementation in question 1 is correct and it functions as documented, what is the return value of the following?

var a1 = [2, 4, 5];

var a2 = ["hello"];

function incr(v, i) {

if (v % 2) return v + 1;

}

return map(a1, incr, a2);

  1. You have an array A of unique integers.

Given an array B of integers that is a subset of array A, reorder the matching integers in array A according to the order of array B.

Example:

array = [3, 5, 6, 7, 2, 0];

reorder(array, [7, 5, 0]);

array becomes [3, 7, 6, 5, 2, 0]

function reorder(array, order) {

// TODO: Implement.

}

  1. What is the time complexity of your solution to question 3?

array size = n

order size = m

complexity = ?

submitted by /u/carloszzzzz777
[link] [comments]

from Web Development and Design https://ift.tt/2Z3GMQD
via IFTTT

No comments:
Write Your Comments

Ready Monetized Blogger Gaming Website