I aced ๐Ÿš€ most Javascript Tech rounds using this Cheatsheet ๐Ÿ“‘ so that you donโ€™t have to go-through all the concepts.

Amerrnath
Geek Culture
Published in
7 min readDec 16, 2022
nintendo controller cheatcode

๐Ÿ“š Hereโ€™s my backstory in creating this cheatsheet for cracking Javascript interviews.

My interview moved past the HR round, and the next (obvious) task I received was a coding challenge. I had less than a week to prepare for it, and I opened my Leetcode challenges to crunch through the problems and optimize my code to O(n) so that I gained enough confidence.

The day came when I had to do the coding challenge, I open the test portal, and my stress level shoots up (as it always does) and becomes worse every minute.

I analyzed the problem statement and the core algorithm pattern to solve it. I start by declaring the variables for input and output (just to reduce my stress) and then by solving an easy variant of the problem with zero input or even sample inputs from the problem statement.

Okay! So I have declared an array for the input, But how do I search an item, and how do I remove an item? ๐Ÿค” is it splice or slice, does splice takes two or three arguments, does it affects the original array, or just return a new array instead, how do I add an item to the front of the array? ๐Ÿ˜ต. If its a live coding challenge, even the slightest sign of heavy breathing from the interviewer can drop a nuke ๐Ÿ’ฃ on my Brain

Photo by Daniel Mingook Kim on Unsplash

I lose my confidence when my mind second guesses a particular method that I have practiced and used literally 1000 times but forget during the interview moment where I should be putting my best self.

A Step backward after making a wrong turn, is a step in the right direction

- KURT VONNEGUT

Regaining your muscle memory ๐Ÿ’ช

Once you have crossed the intermediate language skill tree certain problem scenarios and language methods act as a muscle memory for you so during your development you think about what it solves rather than how it solves . These memory must be strengthen before your interview

Photo by Volodymyr Hryshchenko on Unsplash

ex: Array.sort you know the result will bed sorted rather than how Array.sort is implemented, what algorithm it uses to solve it.

I faced many failures during the Problem solving round, which test your tech skills and deep understanding your domain knowledge.

Failing in Job interview is a probability of 0.9, out of all candidates they will chose one, but your aim is to move the goal post in clearing number of rounds in that job interview(clearing 5 out 6 rounds is still a Victory ๐ŸŽŠ).

Over the 8+years in frontend tech, i have improved and optimised the success rate of clearing a tech round from 60% to 95%, each iteration to optimise my process and reducing the time spent on the thinking correct data structures and methods.

All Problem solving tech rounds involves you to solve the problem using your comfortable language, and Javascript is my swiss knife. Each language comes with its own pre-baked utils or functionality to solve the problem.

Interview CheatSheet ๐Ÿ“‘

I have gone through my leetcode problems and these are the common operation pattern i have observed and created this Interview cheatsheet.

The below mentioned method saves you time, and gives a positive impression to the interviewer. Iโ€™m going to explain how they can be useful rather than how it works under the hood. MDN is best available documentation for Javascript.

This guide will be your supplement guide/tool and its not a replacement algorithm concepts and problem solving techniques.

Photo by Patrick on Unsplash

Array

  • splice โ€” Inserting/Replacing items, permanent effects on Array.
splice(start, deleteCount, item1, item2, itemN)
const months = ['Jan', 'March', 'April', 'June'];
months.splice(1, 0, 'Feb');
// output: Array ["Jan", "Feb", "March", "April", "June"]
months.splice(4, 1, 'May');
// replaces 1 element at index 4
// output: Array ["Jan", "Feb", "March", "April", "May"]
  • slice โ€” Accessing Subset of Array. Mostly used in nested loops concepts. -1 value helps to remove till end of list.
    (ex: `array_items.slice(i,j)` where i represents the outer loop reference and j reference the inner loop)
slice(start, end)
const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];
console.log(animals.slice(2));
// output: Array ["camel", "duck", "elephant"]
console.log(animals.slice(2, 4));
// output: Array ["camel", "duck"]
  • every โ€” To verify that all items in the array have satisfied the expression.
  • some โ€” To verify at-least one item satisfies, effective as it stops the run-loop if the expression has been satisfied.
  • from โ€” shallow copy for array or transform string to Array.
Array.from(โ€œlevelโ€) -> [โ€˜lโ€™, โ€˜eโ€™, โ€˜vโ€™, โ€˜eโ€™, โ€˜lโ€™]
  • fill โ€” Initialise the state of solutions with constraints.
To create m*n array. Array(m).fill(1)
Input: numRows = 5
Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
var generate = function(numRows) {
let result = [];
let i = 1;
while(i <= numRows) {
let prev = result[i-2];
let temp = new Array(i).fill(1).map((j, index) => {
if(index == 0 || index == i-1) {
return j;
}
return prev[index] + prev[index -1];
});
result.push(temp);
i++;
}
return result;
};

Here in this simple leet code problem, if you have noticed the logic, i have used fill, which by defaults add the value to initiated Array, which reduces my compilation time in iterating each row and filling up the value.

  • flat โ€” Array with nested array, need to calculate or access all the item .
ex: sum of all items a = [1,[2], [[3]]] -> a.flat(2)
  • includes โ€” To check item exist in the array.
  • reduce โ€” Underrated method in array, most of the solutions require you do operation on the items and send the result along to next iteration.
  • shift ,unshift โ€” To remove/add the first element opposite to pop/push
  • sort โ€” Sort your items in ascending or descending order, mostly used in start or end of the solutions.
  • join โ€” Merges the items in array by specified string. Heavily used if the operation involve Array to string transformation for the final results.

String

  • replace โ€” Replace character in your string. i would recommend using regex as it gives positive impression on you.
  • split โ€” Transform your string into array of items using a dividing character.
  • test โ€” To test your string against a regex
  • charAt โ€” To find position of character in the string, used in problems like anagram/permutation & combination string problems
  • includes โ€” To find a case-sensitive search, if one string may be found in other string

Object

  • hasOwn/hasOwnProperty โ€” To check if there is key/prop in the object
  • Object coercion

Math

Most of Tree problems involves use of Math operation to compare values between the nodes.

  • Math.min
  • Math.max
  • Math.Infinity
  • Math.sign

Set

Most of the matrix problems involves using a list of item with frequent operation to lookup the item in list to add/delete/search.
Set has better advantage than traditional array.

Set doesnโ€™t allow duplicates values

  • has โ€” Locating the element within the set
  • add/delete โ€” Inserting and Removing the items in the set.
var set = new Set([1,2,3]);
set.has(1) // true
set.add(1) // {1,2,3} no duplicates allowed
set.delete(1) // {2,3}

Map

Map is best way to organise your records, it provides object with precise types for key and value.

Like traditional Object which converts all the keys to string, map use the same object as type without transformation.

const map = new Map([1, โ€œsmileโ€], [2, โ€œcryโ€], [42, โ€œhappyโ€])
map.get(42) // output: "happy" (42 is not string its a number)
// Easy for iterating the contents of the map
for (const [key,value] of map){
console.log(`key: ${key}, value: ${value}`);
}
map.size // 3 (no of records in the map)

Other Concepts ๐Ÿซ

  • Function (Bind, apply, call โ€” Make sure you know the right difference between them as it might be helping during tech interview)
  • Closures
  • Scopes
  • Hoisting
  • SetTimeout/SetInterval
  • Callback/Promise
  • Memoization

Conclusion ๐Ÿ”š

Skim this List before your interview so that you can focus on using most frequently needed operations in coding interviews.

Photo by Long Phan on Unsplash

Implementing this operations/methods in your code gives away a better impression of yourself and makes your mile apart from the rest of the candidates.

Please follow me on twitter https://twitter.com/amerrnath21/

--

--

Amerrnath
Geek Culture
Writer for

Frontend Developer, startup enthusiast, growth hack reader, #react . Traveller