\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{longmatt} \pdfinfo{ /Title (whiteboard-interview.pdf) /Creator (Cheatography) /Author (longmatt) /Subject (Whiteboard Interview Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Whiteboard Interview Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{longmatt} via \textcolor{DarkBackground}{\uline{cheatography.com/195565/cs/40992/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}longmatt \\ \uline{cheatography.com/longmatt} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 23rd October, 2023.\\ Updated 23rd October, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{1.44333 cm} x{3.53367 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Big O Notation}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Definition:} & Way of estimating the complexity of an algorithm by measuring how it's operations scale as the input size grows \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Worst Case: & Big O is only concerned with the worst case scenario \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{Simplification:} & Constants do not matter. Smaller terms do not matter. Always know what n is \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} Hints: & Arithmetic is constant as is variable assignment and accessing elements in an array or object by index or key; \tn % Row Count 13 (+ 4) % Row 4 \SetRowColor{LightBackground} Common Runtimes: & Constant: O(1) Logarithmic O(log n) Linear O(n) Logarithmic O(n log n) Quadratic O(n2) Exponential O(2n) \tn % Row Count 17 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.74655 cm} x{4.23045 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Stacks and Queues}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Queues:} & First in first out. Items only added to the back and only removed from the front. Use linked lists for implementation because removing from the front of an array is O(n) \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \seqsplit{Stacks:} & Last in first out. Items only added and removed from the back (or top like a stack of pancakes). Arrays are fine for stacks because push and pop are both O(1) \tn % Row Count 10 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.4931 cm} x{3.4839 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Trees}} \tn % Row 0 \SetRowColor{LightBackground} Trees: & A data structure that organizes and stores data in a hierarchical tree like fashion. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Tree \seqsplit{Terminology:} & Node: basic unit, children: nodes directly below a node, descendants: nodes below a node, parent: node directly above a node, ancestor: node above a node, root: node at the top of the tree, leaf node: node without any children \tn % Row Count 12 (+ 9) % Row 2 \SetRowColor{LightBackground} Tree examples: & Filesystems, HTML DOM, Taxonomy \tn % Row Count 14 (+ 2) % Row 3 \SetRowColor{white} Types: & n-ary tree's can have any number of children. Binary trees: trees where each node has 0,1 or 2 children \tn % Row Count 18 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.14471 cm} x{3.83229 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Graphs}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Definition:} & Like trees except the can contain loops (cycles) also relationships can be directed or undirected. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \seqsplit{Terminology:} & Node (Vertex) basic unit, Edge: connects two nodes, Adjacent: two nodes that share an edge, Weight: optional parameter for edges (like price) \tn % Row Count 9 (+ 5) % Row 2 \SetRowColor{LightBackground} Node Class: & just needs this.name and this.adjacent \tn % Row Count 11 (+ 2) % Row 3 \SetRowColor{white} Graph Class: & this.nodes = new Set( ) \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Bubble and Merge Sort Example}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{function bubbleSort(arr)\{ \newline for(let i = 0; i \textless{} arr.length; i++)\{ \newline for(let j = 0; j \textless{} arr.length-i; j++)\{ \newline console.log(arr); \newline if(arr{[}j{]} \textgreater{} arr{[}j + 1{]})\{ \newline let newVal = arr{[}j + 1{]}; \newline arr{[}j + 1{]} = arr{[}j{]}; \newline arr{[}j{]} = newVal; \newline \} \newline \newline \} \newline \newline \} \newline \} \newline \newline const merge = (arr1, arr2) =\textgreater{} \{ \newline let output = {[}{]}; \newline let arrOneIdx = 0; \newline let arrTwoIdx = 0; \newline \newline while (arrOneIdx \textless{} arr1.length \&\& arrTwoIdx \textless{} arr2.length) \{ \newline if (arr1{[}arrOneIdx{]} \textless{} arr2{[}arrTwoIdx{]}) \{ \newline output.push(arr1{[}arrOneIdx{]}); \newline arrOneIdx++; \newline \} else \{ \newline output.push(arr2{[}arrTwoIdx{]}); \newline arrTwoIdx++; \newline \} \newline \} \newline while(arrOneIdx \textless{} arr1.length)\{ \newline output.push(arr1{[}arrOneIdx{]}); \newline arrOneIdx ++ \newline \} \newline while(arrTwoIdx \textless{} arr2.length)\{ \newline output.push(arr2{[}arrTwoIdx{]}); \newline arrTwoIdx ++ \newline \} \newline return output; \newline \}; \newline \newline \newline function mergeSort(arr) \{ \newline if (arr.length \textless{}= 1) return arr; \newline let mid = Math.floor(arr.length / 2); \newline let left = mergeSort(arr.slice(0, mid)); \newline let right = \seqsplit{mergeSort(arr.slice(mid));} \newline return merge(left, right); \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.54287 cm} x{3.43413 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{JavaScript Tricky Parts}} \tn % Row 0 \SetRowColor{LightBackground} Closures: & A closure occurs when a function remembers it's scope even after that function has finished executing. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Scope: & In JavaScript, scope refers to the context in which variables and functions are declared and can be accessed. There are two main types of scope: global scope (accessible from anywhere in your code) and local scope (limited to a specific function or block of code). \tn % Row Count 14 (+ 10) % Row 2 \SetRowColor{LightBackground} Nested Functions: & When you have a function defined inside another function, the inner function has access to the variables and parameters of the outer function. This is where closures come into play. \tn % Row Count 21 (+ 7) % Row 3 \SetRowColor{white} Closers revisited: & A closure is created when an inner function references variables from its containing (outer) function, and that inner function is returned or passed around. This allows the inner function to maintain access to the outer function's variables even after the outer function has completed its execution. \tn % Row Count 33 (+ 12) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{1.54287 cm} x{3.43413 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{JavaScript Tricky Parts (cont)}} \tn % Row 4 \SetRowColor{LightBackground} Closure use cases: & 1) Data encapsulation, ie create private variables. 2) Function Factories: use closers create and return functions 3) Callback functions 4) Event Handling \tn % Row Count 6 (+ 6) % Row 5 \SetRowColor{white} Prototype: & The prototype is an object on every JS object that contains properties and methods that aren't on the object itself, this allows for the sharing and inheritance of functionality, JS classes use the prototype under the hood. \tn % Row Count 15 (+ 9) % Row 6 \SetRowColor{LightBackground} The 'new' keyword: & The new keyword does four things 1) Creates an empty object 2) Set this to be that object 3) Returns the object 4) Creates a link to that objects prototype \tn % Row Count 21 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.29402 cm} x{3.68298 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Divide and Conquer}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Definition:} & Given a data set divide and conquer removes a large fraction of the data set at each step \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Binary Search: & data must be structured, for example a sorted array \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} Tips: & make sure data is structured, if you can solve it quickly with linear search try binary search. Watch out for one of errors. \tn % Row Count 11 (+ 5) % Row 3 \SetRowColor{white} Runtime: & O(log n) because it cuts the data set in 1/2 each step \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.09494 cm} x{3.88206 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Recursion}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Definition:} & A powerful programing technique that involves a function calling itself \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Loops: & All loops can be written with recursion and visa versa \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} Base Case: & The base case is required, every recursive function needs one it's what tells the function when it's done. Without a base case you'll get a stack overflow. \tn % Row Count 10 (+ 5) % Row 3 \SetRowColor{white} Use Cases: & Filesystems, Fractals, Parsing, Nested Data \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.09494 cm} x{3.88206 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Binary Search Trees}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Definition:} & A binary tree for efficient searching and sorting. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Rules: & 1) Each node must only have at max two children. 2) The nodes are organized where all nodes in the left subtree are \textless{} than the nodes value and all the nodes in the right subtree have values greater than the nodes value. \tn % Row Count 10 (+ 8) % Row 2 \SetRowColor{LightBackground} \seqsplit{Traversal:} & Typically uses recursion for traversal with either In Order, Pre Order or Post Order Traversal methods. \tn % Row Count 14 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{In order example: traverse(node) \{ \newline if (node.left) traverse(node.left); \newline console.log(node.val); \newline if (node.right) traverse(node.right); \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{BFS and DFS}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{class treeNode \{ \newline constructor(val, children = {[}{]}) \{ \newline this.val = val; \newline this.children = children; \newline \} \newline depthFirstFind(val) \{ \newline let toVisitStack = {[}this{]}; \newline while (toVisitStack.length) \{ \newline let current = toVisitStack.pop(); \newline console.log("Visiting", current.val); \newline if (current === val) \{ \newline return current.val; \newline \} \newline \newline for (let child of current.children) \{ \newline \seqsplit{toVisitStack.push(child);} \newline \} \newline \} \newline \} \newline \newline breathFirstFind(val) \{ \newline let toVisitQueue = {[}this{]}; \newline while (toVisitQueue.length) \{ \newline let current = toVisitQueue.shift(); \newline console.log('visiting', current.val); \newline if (current === val) \{ \newline return current; \newline \} \newline for (let child of current.children) \{ \newline \seqsplit{toVisitQueue.push(child);} \newline \} \newline \} \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.74655 cm} x{4.23045 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Whiteboarding Process}} \tn % Row 0 \SetRowColor{LightBackground} Step 1: & Listen carefully \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Step 2: & Repeat the question back in your own words \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Step 3: & Ask clarifying statements like edge cases. \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Step 4: & Write test cases \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} Step 5: & Write down requirements; like arguments, what it returns etc... \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} Step 6: & Write pseudo code \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} Step 7: & Code \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} Step 8: & Test your code, be the computer \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} Step 9: & Try to optimize, clean up code, be prepared to talk about runtime/ Big O \tn % Row Count 19 (+ 3) % Row 9 \SetRowColor{white} Tips: & Use good variable names, don't brush past tricky parts, limit use of built in methods, take your time they want you to think deeply and approach it methodically it's not a race \tn % Row Count 25 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.94103 cm} x{3.03597 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Problem Solving Process}} \tn % Row 0 \SetRowColor{LightBackground} 1) Understand the problem & restate it in your own words, understand the inputs and outputs \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} 2) Explore Examples & start with simple examples, move to more complex examples \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} 3) Break it down & write out the steps, write pseudocode \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} 4) Solve a simpler problem & if your stuck solve the parts of the problem that you can and come back to the hard part \tn % Row Count 12 (+ 4) % Row 4 \SetRowColor{LightBackground} 5) Use tools & debug, console.log etc.... \tn % Row Count 14 (+ 2) % Row 5 \SetRowColor{white} 6) Look back and refactor & clean up code, can you improve performance? \tn % Row Count 16 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Binary Search Example:}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{function binarySearch(arr, val) \{ \newline \newline let leftIdx = 0; \newline let rightIdx = arr.length - 1; \newline \newline while (leftIdx \textless{}= rightIdx) \{ \newline // find the middle value \newline let middleIdx = Math.floor((leftIdx + rightIdx) / 2); \newline let middleVal = arr{[}middleIdx{]}; \newline \newline if (middleVal \textless{} val) \{ \newline // middleVal is too small, look at the right half \newline leftIdx = middleIdx + 1; \newline \} else if (middleVal \textgreater{} val) \{ \newline // middleVal is too large, look at the left half \newline rightIdx = middleIdx - 1; \newline \} else \{ \newline // we found our value! \newline return middleIdx; \newline \} \newline \} \newline \newline // left and right pointers crossed, val isn't in arr \newline return -1; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Recursive Examples}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{/{\bf{ product: calculate the product of an array of numbers. {\emph{/ \newline \newline function product(nums) \{ \newline // base case \newline if(nums.length === 0) return 1; \newline // normal case \newline return nums{[}0{]} }} product(nums.slice(1)) \newline \} \newline \newline /}} longest: return the length of the longest word in an array of words. {\emph{/ \newline \newline function longest(words) \{ \newline // base case \newline if (words.length === 0) return 0; \newline \newline // normal case \newline const currentLength = words{[}0{]}.length; \newline const remainingWords = words.slice(1); \newline const maxLength = longest(remainingWords); \newline return Math.max(currentLength, maxLength); \newline \} \newline \newline \newline /{\bf{ everyOther: return a string with every other letter. }}/ \newline \newline function everyOther(str) \{ \newline // base case \newline if (str.length === 0) return ""; \newline \newline // normal case \newline const currentLetter = str{[}0{]}; \newline const remainingLetters = str.slice(2); \newline return `\$\{currentLetter\}\$\{everyOther(remainingLetters)\}`; \newline \} \newline \newline /}} isPalindrome: checks whether a string is a palindrome or not. */ \newline \newline function isPalindrome(str) \{ \newline // base case \newline if (str.length === 0 || str.length === 1) return true; \newline \newline // normal case \newline if (str{[}0{]}.toLowerCase() === str{[}str.length - 1{]}.toLowerCase()) \{ \newline return isPalindrome(str.slice(1, str.length - 1)); \newline \} else return false; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Frequency Counter and Multiple Pointers Example}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{function findFreq(string)\{ \newline let stringFreq = \{\}; \newline for(let char of string)\{ \newline stringFreq{[}char{]} = stringFreq{[}char{]} + 1 || 1 \newline \} \newline return stringFreq \newline \} \newline \newline function constructNote(messaage, letters) \{ \newline const messFreq = findFreq(messaage); \newline const lettFreq = findFreq(letters); \newline for(let char in messFreq)\{ \newline if(!lettFreq{[}char{]}) return false; \newline if(messFreq{[}char{]} \textgreater{} lettFreq{[}char{]}) return false; \newline \} \newline return true; \newline \} \newline \newline function averagePair(array, target) \{ \newline let left = 0; \newline let right = array.length - 1; \newline while (left \textless{} right) \{ \newline const average = right + left / 2; \newline if (average === target) return true; \newline else if (average \textgreater{} target) right -= 1; \newline else left += 1; \newline \} \newline return false; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Frequency Counter and Multiple Pointers Example}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{function findFreq(string)\{ \newline let stringFreq = \{\}; \newline for(let char of string)\{ \newline stringFreq{[}char{]} = stringFreq{[}char{]} + 1 || 1 \newline \} \newline return stringFreq \newline \} \newline \newline function constructNote(messaage, letters) \{ \newline const messFreq = findFreq(messaage); \newline const lettFreq = findFreq(letters); \newline for(let char in messFreq)\{ \newline if(!lettFreq{[}char{]}) return false; \newline if(messFreq{[}char{]} \textgreater{} lettFreq{[}char{]}) return false; \newline \} \newline return true; \newline \} \newline \newline function averagePair(array, target) \{ \newline let left = 0; \newline let right = array.length - 1; \newline while (left \textless{} right) \{ \newline const average = right + left / 2; \newline if (average === target) return true; \newline else if (average \textgreater{} target) right -= 1; \newline else left += 1; \newline \} \newline return false; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}