DP World Frontend Interview Experience

Palak BansalPalak Bansal
2 min read

I recently interviewed with DP World, and here is the information I can provide.

  1. Flatten an array
const arr = [1,2,[1,1,[34,67,5,1,1,1,[{a: 1}]]]];
const b = [[1,2],0,0,0,[3,[4,5]],[6,7,[[[8],9]]],10];
let newArr = [];

const flatten = (arr) => {
  let len = arr.length;
  for (let i=0; i<len; i++) {
    if(!Array.isArray(arr[i])) 
      {
        newArr.push(arr[i]);
      } else {
      flatten(arr[i]);
    }
  }
}
console.log(flatten([1, 2, 3]));
console.log(newArr);
  1. Provide maximum solutions to form sum from an array with the given target.

     const numbers = [2,3,6,7];
     const target = 7;
    
     function combinationSum(num, target) {
         const result = [];
    
         function backtrack(start, target, path) {
             if (target === 0) {
                 result.push([...path]);
                 return;
             }
    
             for (let i = start; i < num.length; i++) {
                 if (num[i] <= target) {
                     path.push(num[i]);
                     backtrack(i, target - num[i], path);
                     path.pop();
                 }
             }
         }
    
         num.sort((a, b) => a - b); // Sort the numbers
         backtrack(0, target, []); // Start backtracking from the beginning
         return result;
     }
    
     const numbers = [1, 2, 3, 6, 7];
     const target = 7;
     console.log(combinationSum(numbers, target));
    
     /* A solution set is:
     [
       [7],
       [2,2,3]
     ] */
    
    1. How to achieve Privatisation of variables through Javascript?

    2. Explain Function Currying.

    3. Output Question:

       import React, { useState } from "react";
       import { screen } from "@testing-library/dom";
       import userEvent from "@testing-library/user-event";
      
       const A =() => {
         console.log("render A");
         return null;
       }
      
       const App =() => {
         const [_state, setState] = useState(false);
         console.log("render App");
         return (
           <div>
             <button
               onClick={() => {
                 console.log("click");
                 setState(true);
               }}
             >
               click me
             </button>
             <A />
           </div>
         );
       }
      
       userEvent.click(screen.getByText("click me"));
       userEvent.click(screen.getByText("click me"));
       userEvent.click(screen.getByText("click me"));
      
       /*
       click
       render App
       render A
       click
       render App
       render A
       click
       render App
       render A
      
       1. The initial rendering occurs when the App component is first rendered. 
       Both "render App" and "render A" are logged to the console.
       2. When the button with the text "click me" is clicked for the first time, 
       the click event handler sets the state to true, triggering a re-render of the App component. 
       This causes "click" and "render App" to be logged to the console again.
       3. Since the state has changed, React also re-renders the A component, resulting in "render A" 
       being logged again.
       The same process repeats for the second and third clicks
       on the button, resulting in additional "click" and "render" logs.
       */
      

      Apart from this, there were several questions prototypes and data hiding.

      Thank you for Reading!

4
Subscribe to my newsletter

Read articles from Palak Bansal directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Palak Bansal
Palak Bansal

Experienced Frontend Developer with a demonstrated history of working in the financial services industry along with having 5+ years of hands on professional experience efficiently coding websites and applications using modern HTML, CSS and Javascript along with their respective frameworks viz.Vue.JS, React.JS. Instituting new technologies and building easy to use and user-friendly websites is truly a passion of mine. I actively seek out new libraries and stay up-to-date on industry trends and advancements. Translated designs to frontend code along with streamlining existing code to improve site performance. Collaborated with UX designers and Back End Developers to ensure coherence between all parties. Also tested some feature prototypes for bugs and user experience.