Skip to content

Instantly share code, notes, and snippets.

@bmsrox
Forked from andrewmclagan/general.md
Last active July 17, 2020 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmsrox/8cf6d37a1d69c2425d1abdea3fda5b9c to your computer and use it in GitHub Desktop.
Save bmsrox/8cf6d37a1d69c2425d1abdea3fda5b9c to your computer and use it in GitHub Desktop.
Beam Tech Interview - Bruno.

Below are general senior level full stack developer Q&As.


1. GraphQL vs RESTful

List some issues within RESTful APIs that GraphQL attempts to solve.

  • Multiple Resources
  • Number of request
  • Over and Under fetching

2. Dont't Repeat Yourself.

Write a snippet of code violating the Don't Repeat Yourself (DRY) principle. Then, fix it. Use any language.

const fruit = 'apple'

if (fruit === 'apple' || fruit === 'orange') {
  //do something
}

Fixed

if (['apple', 'orange'].includes(fruit)) {
  //do something
}

3. Inheritance vs Composition.

Many state that, in Object-Oriented Programming, composition is often a better option than inheritance. What's you opinion?

Composition is better than Inheritance because the code becomes more flexible, cohesive, testable, and prevents coupling between classes.


4. Test Driven Development

How do tests and TDD influence code design?

TDD and test in general help to develop a quality code. Helps to write a simple code and reusable.


5. Statelessness

Why is developing a backend service (e.g. a Laravel API) as a stateless servie so important? What's the advantages of stateless code?

It's important because we can separate de responsability between frontend and backend, distribute tasks among teams, optimize the development process and some service advantages are horizontal scalability, less use of computational resources, and architecture with simplified design.

Below are senior level frontend javascript developer Q&As.


1. ES6 functional javascript code

Below is an array of people and their pets, along with an array of pet IDs. Write some code that takes two inputs: people and petIds and returns the original people array and for each matching pet id insert a property { species: 'cat' } into matching pet object.

e.g. { id: '2', name: 'Rolf', species: 'cat' }

Demonstrate your most expressive, clean, testable and ES6 compatible code

const petIds = ['2','3','5'];

const people = [
  {
    id: '1',
    name: 'Jill',
    sex: 'female',
    age: 32,
    pets: [
      { id: '1', name: 'Kitty'},
      { id: '2', name: 'Rolf'}
    ]
  },
  {
    id: '2',
    name: 'Sam',
    sex: 'male',
    age: 16,
    pets: [
      { id: '3', name: 'Pretty boy'}
    ]
  },
  {
    id: '4',
    name: 'Pete',
    sex: 'male',
    age: 33,
    pets: [
      { id: '4', name: 'Misty'},
      { id: '5', name: 'Milo'}
    ]
  },
  {
    id: '5',
    name: 'Jess',
    sex: 'female',
    age: 21,
    pets: []
  }  
]
const assignPeoplePetsSpecie = (peopleList, petIdsList) => {
  return peopleList.map(person => {
    person.pets
      .filter(pet => petIdsList.includes(pet.id))
      .map(pet => Object.assign(pet, { species: 'cat' }))
    
    return person
  })
}

2. Dependencies

Define NPM, Yarn and the difference between the two.

Yarn and NPM are package managers that help to manage a projects dependencies. The difference between the two is Yarn has more performance, securely than NPM.

  • Performance: Yarn download packages locally and fetchs from the disk. Don't need to download dependencies more than once,so it can work offline. NPM fetchs from registry.
  • Securely: Yarn ensure that every install is the same package version throughout all devices.

3. Variable scope

What is the purpose of let keyword in javascript?

When we use let, we are assigning block scope to the variable being created and, therefore, no hoisting.


4. Statless components

Explain the reasoning behind a stateless component along with a small code example. Use React or Vue.

Stateless Component it is a pure function, it is easier to be tested and the quality of the code is higher, it only depends on the inputs, which are the props.

import React from "react"
const Test = ({ name }) => <p>Hello {name}</p>
export default Test

Below are PHP / Laravel senior level full stack developer Q&As.


1. Writing clean and testable code

Rewrite the class below to be more testable and clean

class User
{
    public static function getUsersByAge(int $age): ?Collection
    {
        $users = DB::table('users')
            ->where('age', $age)
            ->get();

        if ($users->count() > 0) {
            return $users;
        }

        return null;
    }
}
interface UserRepositoryInterface {
    public function getUsersByAge(int $age): ?Collection;
}
 
class UserRepository implements UserRepositoryInterface {
 
    protected $_db;
 
    public function __construct($db)
    {
        $this->_db = $db;
    }
 
    public function getUsersByAge(int $age): ?Collection
    {
        $db = $this->_db;
        $users = $db::table('users')
            ->where('age', $age)
            ->get();

        if ($users->count() > 0) {
            return $users;
        }

        return null;
    }
 
}
 
class User {
 
    protected $userRepository;
 
    public function __construct(UserRepositoryInterface $user)
    {
        $this->userRepository = $user;
    }
 
    public function getUsersByAge(int $age)
    {
        return $this->userRepository->getUsersByAge($age);
    }
 
}

2. Redis

What are the advantages of using Redis as the cache and queue drivers over the php array driver?

The advantages of using Redis are writing and reading data is extremely fast, store data in memory, allows data to be persisted physically if desired.


3. Eloquent and the database

Explain the differences between eager loading and lazy loading in eloquent models.

  • Lazy Loading: query by a certain Entity its relations are not loaded.
  • Eager Loading: loads all related entities.

4. Modern PHP

What is your favourite language feature introduced in PHP 7.4? Why do you like it? What advantages does it offer?

My favourite language features introduced in PHP 7.4 are Arrow Functions, Typed Properties, and Spread Operator. Because I have some experience with Javascript and these features help a clean and performatic code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment