Giter VIP home page Giter VIP logo

interview-questions-in-javascript's People

Contributors

7kfpun avatar alexdmejias avatar astonm avatar canaandavis avatar craigayre avatar d4rkr00t avatar dommartin27 avatar fundebug avatar httpete-ire avatar kennymkchan avatar vitalyavolyn 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  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

interview-questions-in-javascript's Issues

isPowerOfTwo is absolutely incorrect solution in JS

5.1 is a classic solution in most languages that have real integer types. Unfortunately, JS number is not a real integer. It will fall back to 32-bit signed integer when doing bitwise operations.

Just simply try this:

isPowerOfTwo(2 ** 43 - 2 ** 40)
// true
(2 ** 43 - 2 ** 40).toString(16)
// "70000000000"

Intersection of two Arrays

Find below optimized code for intersection of two arrays:

var firstArray = [2, 2, 4, 1,5,2,3,6,4,22,2];
var secondArray = [1, 2, 0, 2];

intersection(firstArray, secondArray); // [2, 1]

function intersection(firstArray, secondArray) {

let finalArray=[];

for(let i=0;i<firstArray.length;i++){

if(secondArray.indexOf(firstArray[i])> -1){

  
  finalArray.push(firstArray[i]);
}

}

console.log([... new Set(finalArray)]);

}

So much wrong

  • 2.3 has lots of issues:
    • First of all, the second example return false. Go on, run it, look for the mistake, I'll wait here. Here's some lorem ipsum to force a context switch in your brain:
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla diam id tortor vestibulum, a imperdiet mauris lacinia. Sed egestas eros eros, quis eleifend lectus pharetra sit amet. Nullam fringilla finibus velit non euismod. Donec iaculis cursus sapien, quis vestibulum ante interdum vitae. Sed scelerisque scelerisque accumsan. Donec sed orci nisl. Mauris eget aliquet orci. Integer consectetur rhoncus tristique. Aenean quis sodales mauris. Donec fringilla lacus commodo pulvinar euismod. Sed at laoreet dui. Nam consequat vitae ante ut efficitur. Sed vel metus at dui elementum aliquam. Sed et odio sed sem facilisis tristique.
      Still here? Good. I hope you noticed all by yourself that you first remove all non-lowercase letters and then convert the input to lowercase. Thus you remove the uppercase 'C' in the very first step.
    • This is kind of the same mistake: it doesn't work for non-latin characters. Is saös a palindrome? Certainly not! However, after deleting the non-latin letter, it suddenly is, causing a false positive.
    • In case you now got the insane idea to list all printable characters and are about to write something like replace(/[^A-Za-zäöüÄÖÜßłŧøþæſðđŋħĸłΩŁŦ¥ıØÞÆẞÐŊĦŁ]+/g,"") or something like that, here's a better idea: first convert to lowercase, then filter out all whitespace. And just in case you get the idea to write .toLowerCase().replace(/[ \t\r\n]/g,"") (which obviously leaves out the less common whitespace things like zwnbsp or half-space), use the character group instead of trying to reinvent a broken wheel. In short, the following works: .toLowerCase().replace(/\s/g, "") (At least it works much better.)
  • 3.2 uses a stack for the sake of using a stack. Instead, one could just keep a counter of currently open parenthesis: increase if a ( is encountered, and decrease if a ) is encountered. If at any point in time the counter becomes negative, it's invalid. If the counter is non-zero in the end, it's invalid. In all other cases, it's valid.
  • How is 4.1 a "question in javascript"?
  • 5.1 is recursive for the sake of being recursive. This introduced a subtle error that now is hard to fix: decimalToBinary(0) returns "0"

And finally:

  • "A mostly reasonable" -> in what regard "reasonable"? None of these questions prove any knowledge about JS. In fact, you could ask them in any other question as well. How about more javascript-y questions like "Where and how can you include a script into a web page? When and why do you choose each method?" or "How do you efficiently detect whether some animated element is no longer visible and start/stop the animation appropriately?" or something like that.
  • "collection" -> from where did you scrape these? Google knows a lot more and a lot better questions.
  • "of technical software development interview questions" -> says who? Source? Just imagine you're a manager of a team. You want to write the next GitHub or whatever. Would you be comfortable employing someone who only proved that yes, they know how to sort an array? Also, what's the point of using a built-in function? Do you just want to test whether they have memorized the entire documentation and know everything by heart? What for?

make js files for every example

It might be easier for people to understand the implementation of the examples if they can run the code and play around with it. It would also be nice to have tests for each example.

I can help out with this if you think it might be helpful 😺

Question 1.2 for loop missing a return keyword

function findMissingNumber(arrayOfIntegers, upperBound, lowerBound) {
  // Iterate through array to find the sum of the numbers
  var sumOfIntegers = 0;
  for (var i = 0; i < arrayOfIntegers.length; i++) {
      return sumOfIntegers += arrayOfIntegers[i];  <---- this is the missing return keyword
  }

  // Find theoretical sum of the consecutive numbers using a variation of Gauss Sum.
  // Formula: [(N * (N + 1)) / 2] - [(M * (M - 1)) / 2];
  // N is the upper bound and M is the lower bound

  upperLimitSum = (upperBound * (upperBound + 1)) / 2;
  lowerLimitSum = (lowerBound * (lowerBound - 1)) / 2;

  theoreticalSum = upperLimitSum - lowerLimitSum;

  return theoreticalSum - sumOfIntegers;
} 

1.1 - why is greatest product either (min1 * min2 * max1 || max1 * max2 * max3)

Hi. Looking at https://github.com/kennymkchan/interview-questions-in-javascript#array--product, a comemnt says // greatest product is either (min1 * min2 * max1 || max1 * max2 * max3)
Surely the greatest product is the one with from max1 * max2 * max3, where does min1 * min2 * max1 come from? Or am I missing something?

function computeProduct(raw_data) {
    return raw_data
            .sort((a, b) => Math.abs(a) - Math.abs(b))
            .slice(-3)
            .reduce((accumulator, num) => accumulator * num);
}

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.