Skip to content

Instantly share code, notes, and snippets.

View ninadvadujkar's full-sized avatar
🎯
Focusing

Ninad Vadujkar ninadvadujkar

🎯
Focusing
View GitHub Profile
@ninadvadujkar
ninadvadujkar / flattenArrayOfObjects.js
Last active November 18, 2022 07:57
Flatten a nested array of objects
const data = [
{
id: 251,
name: 'Top level 1',
parentId: null,
children: [
{
id: 253,
parentId: 251,
name: 'Inner level 1-1',
@ninadvadujkar
ninadvadujkar / array-reduce-basics.js
Last active January 3, 2022 12:27
Basic usage of Array.reduce
// 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?
@ninadvadujkar
ninadvadujkar / guidelines.md
Last active June 10, 2021 10:00
Guidelines for HCL Hands-on Test

Guidelines

General Guidelines

  • 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 any type. 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.
Phases
1. Initialisation
2. Mounting
3. Updating
4. Unmounting
1. Initialisation
Setting up of initial state and default props happen here.
a. constructor
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]]
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 = [];
}
@ninadvadujkar
ninadvadujkar / retry.interceptor.ts
Last active April 3, 2023 08:54
A basic Angular HTTP Interceptor to retry requests when there's an error
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;
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) {}
import React, { Component } from 'react';
class FormTest extends Component {
constructor(props) {
super(props);
this.state = {
username: {
value: '',
valid: false,
errorMessage: ''
@ninadvadujkar
ninadvadujkar / angular_lifecycle_hooks.txt
Last active May 28, 2018 07:10
Text about Angular lifecycle hooks extracted from codecraft.tv Angular course
Lifecycle hooks Angular
constructor
ngOnChanges
ngOnInit
ngDoCheck
ngAfterContentInit
ngAfterContentChecked
ngAfterViewInit
ngAfterViewChecked