Skip to content

Instantly share code, notes, and snippets.

@mateja176
Last active August 20, 2021 07:07
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 mateja176/e32ddab3c803d7e58597e10f801a60a9 to your computer and use it in GitHub Desktop.
Save mateja176/e32ddab3c803d7e58597e10f801a60a9 to your computer and use it in GitHub Desktop.
  • HTML
    • HTML page
    • tags
    • semantic HTML
    • style tag
    • script tag
      • blocking: async+defer
    • form tag
      • input tag and variants
  • CSS
    • box model
    • positioning
    • responsiveness
    • transitions
  • JS
    • arrays
    • objects
    • ES6+
      • Arrow functions
        • What are they?
        • Arrow functions vs regular functions
      • Promises and async await
      • modules
      • rest and spread operator
    • FP in JS
      • immutable array update methods
        • map
        • filter
        • reduce
      • immutable object update methods
        • Object.entries
        • Object.fromEntries
    • libraries
      • lodash
      • uuid
    • browser API's
  • React
    • hooks
    • state management
    • component styling & styled-components
    • design systems component libraries
    • component development & Storybook
    • @testing-library/react
    • server side rendering & Razzle
    • form management & react-hook-form
    • wai-aria & Reakit
    • data fetching and caching & urql
      • implementing loading states: best practices
      • error handling
    • clean code in React
    • routing & React router
    • charts
    • lazy loading
    • concurrent mode and Suspense
    • react-helmet
  • NodeJS
    • NestJS
    • express
    • apollo-server-express
  • SQL
    • What is SQL
    • SQL DB's
    • SQL vs NoSQL
    • ORM's
      • Why?
      • Sequalize
    • Postgres
    • SQL GUI's
      • pgadmin
  • git
    • staging
    • committing
    • commit message convections
    • resetting and restoring
    • branches
    • rebase
    • cherry-picking
    • bisecting
  • Analytics
    • What, how, why?
    • Segment
    • TypeWriter
  • TypeScript
    • JS vs TS
    • basic types
    • unions and intersections
    • generics
    • type guards
    • type assertions
    • utility types
    • TS and React
      • ReactElement and ReactNode
      • prop types
      • generic components
  • Yarn/NPM
    • installing, upgrading and removing dependencies
  • package.json
    • scripts
    • hooks
  • Testing
    • e2e testing & Cypress
    • unit testing & Jest
  • Networking
    • HTTP
      • Methods
      • HTTP message format
      • Encryption
  • GraphQL
    • GraphQL vs REST
    • GraphQL Schema
    • GraphQL Syntax
    • codegen
  • Serverless & AWS
    • IAM: cognito
    • static file storage: S3
  • Docker
  • Kubernetes
    • load balancing
    • rolling updates
    • control plane
    • kubelet
    • Pods and workloads
  • Redis
  • Debugging
  • UX/UI
    • contrast
    • fonts
    • spacing
    • popups
    • focusing attention
    • consistency
    • signalling interactivity
  • Cross-browser compatibility
    • What are the best practices?
  • Web performance
    • Lighthouse
    • Webpage test
  • SEO
    • Sitemap
    • meta tags
  • Github
    • tracking remote branches
    • PR's
  • CI/CD
    • Linting
    • Formatting
    • Formatting
  • Agile software development
    • Jira
interface Person {
name: string;
age: number;
gender: 'male' | 'female';
student: boolean;
}
const persons: Person[] = [
{
name: 'Bob',
age: 32,
gender: 'male',
student: false,
},
{
name: 'Alice',
age: 30,
gender: 'female',
student: false,
},
{
name: 'Philip',
age: 22,
gender: 'male',
student: true,
},
{
name: 'Sam',
age: 24,
gender: 'male',
student: true,
},
{
name: 'Anna',
age: 28,
gender: 'female',
student: false,
},
];
// 1. Create a linked list out of the array, where the linked items are of the following type:
interface LinkedItem extends Person {
next: LinkedItem | null;
}
const linkedList = persons.reverse().reduce<LinkedItem[]>((list, person, i) => {
const next = list[i - 1];
return list.concat({ ...person, next: next ?? null });
}, []);
// const linkedList = persons.reduceRight<LinkedItem[]>(
// (list, person, i, array) => {
// const next = list[array.length - i - 2];
// return list.concat({ ...person, next: next ?? null });
// },
// [],
// );
console.log(linkedList);
// 2. Reverse the linked list
const reverse = (item: LinkedItem | null, people: Person[]): Person[] => {
if (item) {
const { next, ...person } = item;
return reverse(item.next, people.concat(person));
} else {
return people;
}
};
const people = reverse(linkedList[linkedList.length - 1], []);
console.log(people);
console.log(typeof (1 < 2));
console.log(typeof (1 - 2));
console.log(typeof true);
console.log(typeof !1);
console.log(typeof +false);
console.log(typeof {});
console.log(typeof []);
console.log(typeof null);
console.log(typeof NaN);
console.log(typeof undefined);
console.log(typeof (() => {}));
console.log(typeof typeof (() => {}));
console.log(typeof 1 - 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment