Skip to main content
Image

r/javascript


[AskJS] How to solve this kind of tricky question in 20 minutes ? A challenging coding question I was asked in a recent Paytm interview [AskJS] How to solve this kind of tricky question in 20 minutes ? A challenging coding question I was asked in a recent Paytm interview
AskJS

The problem was to convert a flat object with dot-separated keys into a properly nested object/array structure.

Example

Input

const input = {
  name: 'Saksham',
  'skills.domain.fe.0': 'React',
  'skills.domain.fe.1': 'Next.js',
  'skills.domain.be.0': 'Node',
  'skills.domain.be.1': 'Express',
  'skills.experience': 3,
  'projects.0.title': 'FitConnect',
  'projects.0.tech.frontend': 'React',
  'projects.0.tech.backend': 'Node'
};

Expected Output

{
  name: "Saksham",
  skills: {
    domain: {
      fe: ["React", "Next.js"],
      be: ["Node", "Express"]
    },
    experience: 3
  },
  projects: [
    {
      title: "FitConnect",
      tech: {
        frontend: "React",
        backend: "Node"
      }
    }
  ]
}

Your cloud setup should reduce stress, not add to it. With Azure, your apps scale automatically, your tools stay organized, and threats are caught early.
  • Image
    Try Azure Free
  • Image
    Try Azure Free
  • Image
    Try Azure Free
  • Image
    Try Azure Free
  • Image
    Try Azure Free