Giter VIP home page Giter VIP logo

danieldelcore / mega-interview-guide Goto Github PK

View Code? Open in Web Editor NEW
1.1K 20.0 127.0 748 KB

The MEGA interview guide, JavaSciript, Front End, Comp Sci

Home Page: https://danieldelcore.github.io/mega-interview-guide/

License: MIT License

CSS 15.84% HTML 61.98% JavaScript 22.18%
interview-questions interview frontend questions-and-answers questions data-structures javascript sort algorithms computer-science

mega-interview-guide's Introduction

Shows an illustrated sun in light color mode and a moon with stars in dark color mode.

Hi, I'm Daniel ๐Ÿ‘‹ Thanks for visiting my MySpace Github!

PROJECTS

INTERESTS

Design Systems, Threejs, CSS-in-JS, Codemods and mentorship!

I'm always open for a chat so feel free to reach out to me on Twitter

SPONSORS

Huge thanks for all of the support from my sponsors!

@omeraplak @necatiozmen @PreciselyAlyss @PreciselyAlyss

mega-interview-guide's People

Contributors

bikashdaga avatar danieldelcore avatar dependabot[bot] avatar eshwarchandra avatar hangindev avatar joeyqlim avatar msmfa avatar torifat avatar wellyshen avatar yangshun avatar zainafzal08 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mega-interview-guide's Issues

Thanks!

This is a great resource. Thanks for making it! โ™ฅ๏ธ

Vision & Goals

First of all, thanks for putting in all that effort and then sharing it with the community โค๏ธ


I was thinking about contributing some of the missing bits, although I'm unsure how far I should go with some solutions. And, is my appraoch aligned with your visions and goals for this initiative.

For example, I was looking at "Verify a prime number?". Now the current solution is-

const isPrime = (num) => {
  for (let i = 2; i < num; i++) if (num % i === 0) return false;

  return num > 1;
};

There are a few things we can do here:

  1. Replace this version with a bit efficient version.
  2. Add a step-by-step example of how we can improve it.
  3. Replace this version with the most efficient version.
  4. Add external resources.

Keen to know your thoughts. Which one would you prefer?


Here's a version I'm fiddling with now:

The simplest approach is to check if num is divisible by every integer less than num.

const isPrime = (num) => {
  for (let i = 2; i < num; i++) if (num % i === 0) return false;

  return num > 1;
};

A more efficient approach is to check if the num is divisible by every integer up to its square root.

Should we explain why one of the factors should always be less or equal to the square root of a number?

const isPrime = (num) => {
  const limit = Math.sqrt(num);
  for (let i = 2; i <= limit; i++) if (num % i === 0) return false;

  return num > 1;
};

A slightly more efficient approach is also to avoid all even numbers since they are divisible by 2; hence can't be prime.

const isPrime = (num) => {
  if (num % 2 === 0) return num === 2;
  const limit = Math.sqrt(num);
  for (let i = 3; i <= limit; i+=2) 
      if (num % i === 0) return false;
  return num > 1;
};

We can keep creating slightly more efficient versions by eliminating multiples of known primes.

  1. Should we explain how they can derive this from 6k + i or even write more efficient versions following the same pattern (p1 * p2 * ... * pn)k + i?
const isPrime = (num) => {
  if (num % 2 === 0) return num === 2;
  if (num % 3 === 0) return num === 3;
  const limit = Math.sqrt(num);
  for (let i = 5; i <= limit; i+=6) 
      if (num % i === 0 || num % (i + 2) === 0) return false;
  return num > 1;
};

Here's the result of not very scientific benchmark I did ๐Ÿ˜…

Screen Shot 2021-07-21 at 6 55 55 pm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.