- Write appropriate unit tests for your code. Try to cover 100% of your code. Write tests for positive as well negative outcomes. Take edge cases into account.
- If the problem is in Typescript, use default and custom types diligently. Please do not use
anytype. We care about type safety and you should too. - Make sure your code is well written and follows proper coding conventions.
- Add useful comments wherever required
- Lint your code
- Use user-friendly, readable variable names etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const data = [ | |
| { | |
| id: 251, | |
| name: 'Top level 1', | |
| parentId: null, | |
| children: [ | |
| { | |
| id: 253, | |
| parentId: 251, | |
| name: 'Inner level 1-1', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Basic usage of reduce to find sum of numbers in an array | |
| const numbers = [1, 2, 3, 4, 5]; | |
| const sum = numbers.reduce((prev, curr) => prev + curr, 0); | |
| console.log('sum', sum); | |
| // Basic usage of reduce to convert an array of objects into an object. | |
| // For e.g. | |
| // Input -> [{ id: 1, key: 'a', value: 'a' }, { id: 2, key: 'b', value: 'b' }, { id: 3, key: 'c', value: 'c' }]; | |
| // Output -> { 1: { key: 'a', value: 'a' }, 2: { key: 'b', value: 'b' }, 3: { key: 'c', value: 'c' } }; | |
| // Now you might ask, what's the use of this and where we might use this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Phases | |
| 1. Initialisation | |
| 2. Mounting | |
| 3. Updating | |
| 4. Unmounting | |
| 1. Initialisation | |
| Setting up of initial state and default props happen here. | |
| a. constructor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| What is [[Prototype]]? | |
| Every object has a special hidden property called [[Prototype]] which is used to access that object's prototype. | |
| prototype object <- [[Prototype]] <- object | |
| [[Prototype]] is hidden and internal | |
| __proto__ can be used to set [[Prototype]] | |
| Fun fact: | |
| 1. __proto__ is a historical getter/setter for [[Prototype]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function explode(array, chunkSize) { | |
| if (chunkSize === 0) return []; | |
| const explodedArr = []; | |
| let innerArr = []; | |
| for (let i = 0; i < array.length; i++) { | |
| innerArr.push(array[i]); | |
| if ( (i + 1) % chunkSize === 0) { | |
| explodedArr.push(innerArr); | |
| innerArr = []; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Injectable } from '@angular/core'; | |
| import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http'; | |
| import { Observable, timer, throwError, of } from 'rxjs'; | |
| import { retryWhen, tap, mergeMap } from 'rxjs/operators'; | |
| @Injectable() | |
| export class HttpRequestInterceptor implements HttpInterceptor { | |
| retryDelay = 2000; | |
| retryMaxAttempts = 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Injectable } from '@angular/core'; | |
| import { HttpClient } from '@angular/http'; | |
| import { Observable } from 'rxjs'; | |
| import { concatMap } from 'rxjs/operators'; | |
| @Injectable({ | |
| providedIn: 'root' | |
| }) | |
| export class TestService { | |
| constructor(private readonly _http: HttpClient) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react'; | |
| class FormTest extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| username: { | |
| value: '', | |
| valid: false, | |
| errorMessage: '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Lifecycle hooks Angular | |
| constructor | |
| ngOnChanges | |
| ngOnInit | |
| ngDoCheck | |
| ngAfterContentInit | |
| ngAfterContentChecked | |
| ngAfterViewInit | |
| ngAfterViewChecked |