Skip to content

Instantly share code, notes, and snippets.

Frameworks like React require that when you change the contents of an array or object you change it's reference. Or push another way that you don't change arrays but instead create new arrays with updated values (i.e. immutability).

There are older array methods that are incompatible with immutability because they alter the array in place and don't cghange the array reference. These are destructive methods.

Shown below are replacements for the array destructive methods (e.g. push, pop, splice, sort, etc.) that will create new array references with the updated data.

Solutions are provided using the spread operator and also the newer "change array by copy" methods (toSpliced, toSorted, toReversed and with).

Setting Value At Index

@sbmadhav
sbmadhav / review-checklist.md
Created April 9, 2023 20:07 — forked from bigsergey/review-checklist.md
Front-end Code Review Checklist

Review checklist

General

  1. Does the code work?
  2. Description of the project status is included.
  3. Code is easily understand.
  4. Code is written following the coding standarts/guidelines (React in our case).
  5. Code is in sync with existing code patterns/technologies.
  6. DRY. Is the same code duplicated more than twice?

Interview Questions

Node.js

Q1: What do you mean by Asynchronous API? ☆☆

Answer: All APIs of Node.js library are aynchronous that is non-blocking. It essentially means a Node.js based server never waits for a API to return data. Server moves to next API after calling it and a notification mechanism of Events of Node.js helps server to get response from the previous API call.

Source: tutorialspoint.com

@sbmadhav
sbmadhav / Errors-resolved.md
Created October 10, 2020 01:05
Errors I have encountered and resolved

Errros I have encountered and resolved

NVM and VSCode

VSCode would throw error like below:

nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local"
Run `npm config delete prefix` or `nvm use --delete-prefix v8.8.1 --silent` to unset it.
@sbmadhav
sbmadhav / vscode-extensions.md
Last active September 22, 2020 02:59
VS code Extensions you need

The VS code extensions I use all the time

Code

Formatter

  1. Prettier - Code formatter
  • Id: esbenp.prettier-vscode
  • Description: Code formatter using prettier
@sbmadhav
sbmadhav / git-life-savers.md
Created September 22, 2020 01:41
Life saver git commands

Delete branches that did not receive commits more than 4 weeks

    for k in $(git branch | sed /\*/d); do 
      if [ -n "$(git log -1 --since='12 weeks ago' -s $k)" ]; then
        git branch -D $k
      fi
    done

Log branches in order of commits received

    for branch in `git branch -r | grep -v HEAD`; do 

echo -e git show --format="%ci %cr %(committerdate) %09 %(authorname) %09 %(refname)" $branch | head -n 1 \t$branch;

@sbmadhav
sbmadhav / delete-2-month-old-branches.sh
Last active September 22, 2020 01:38
Delete git branches that did not receive any commits in the last two months
#!/bin/bash
for k in $(git branch -r | sed /\*/d); do
if [ -z "$(git log -1 --since='2 months' -s $k)" ]; then
branch_name_with_no_origin=$(echo $k | sed -e "s/origin\///")
# echo deleting branch: $branch_name_with_no_origin
git push origin --no-verify --delete $branch_name_with_no_origin
fi
done