Skip to content

Instantly share code, notes, and snippets.

String input = '''
Some text here
## Hello World
Thanks for ## nice reading.
## New Heading
''';
// Output:
// Some text here
// <h2>Hello World </h2>

Resistor Networks

Resistors are electrical components that add resistance to a circuit. Resistance is measured in ohms. When resistors are connected in series, the total resistance is merely the sum of the individual resistances:

Rtotal = R1 + R2 + R3 + ...

When resistors are connected in parallel, the reciprocal of the total resistance is equal to the sum of the reciprocals

function isbn13(input){
let isbn = Array.from(input);
// console.log(isbn)
isbn[9] = isNaN(isbn[9])? 10 : isbn[9];
isbn = convertForChecking(isbn);
if(isbn.reduce((a, b) => Number(a) + Number(b), 0) % (isbn.length === 10 ? 11 : 10) === 0){
return isbn.length === 13
? 'Valid'
: convertToIsbn13(input)
}

Convert a Binary Tree to an Array

Given a binary tree of Javascript objects, return an array representing that tree. The array has the same definition as in Cousins in Binary Tree - Part 3.

For example,

treeToArray(
    {
 value: 1,

Find All Digits

Taking each number of an array in turn, return the number that you are on when all of the digits 0-9 have been discovered. If not all of the digits can be found, return "Missing digits!".

Examples

findAllDigits([5175, 4538, 2926, 5057, 6401, 4376, 2280, 6137, 8798, 9083]) ➞ 5057
// digits found:  517-  4-38  29-6  -0

findAllDigits([5719, 7218, 3989, 8161, 2676, 3847, 6896, 3370, 2363, 1381]) ➞ 3370

Averages Methods: Extending the Math Object

Catchup Exercise

In this exercise the goal is to extend the Math() object adding four methods for calculate different types of averages.

  • Arithmetic Mean: The division of the sum of the numbers by the quantity of numbers.
    • avg of [A, B, C] ➞ (A + B + C) / 3
  • Quadratic Mean: Also called Root Mean Square, is the square root of the arithmetic mean of the squared numbers.
    • qAvg of [A, B, C] ➞ ²√ ( (A² + B² + C²) / 3 )

Mind the Gap

A number is gapful if it is at least 3 digits long and is divisible by the number formed by stringing the first and last numbers together. The smallest number that fits this description is 100. First digit is 1, last digit is 0, forming 10, which is a factor of 100. Therefore, 100 is gapful.

Create a function that takes a number n and returns the closest gapful number (including itself). If there are 2 gapful numbers that are equidistant to n, return the lower one.

Examples

Restore IP Addresses

Given a string containing only digits, restore it by returning all possible valid IP address combinations.

A valid IP address consists of exactly four integers (each integer is between 0 and 255) separated by single points.

Examples

Input: "25525511135"
Output: ["255.255.11.135", "255.255.111.35"]

Grocery Prices in Base Currency

Time Allowed: 1 hour

Create an async function which calculates the total price of a given grocery list in a given curency for a given date

  • Replace $ with USD, € with EUR, ₹ with INR and £ with GBP
  • Use 2 regular expression capturing groups to pick out (a) the 3-letter currency code; (b) the price
  • Use this website to get exchange rates for a given date.
  • Use the axios package for making an HTTP request in node.js
  • Throw an error if the HTTP response status code is not 200

Number of Boomerangs

Time Allowed: 36 minutes

Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the order of the tuple matters).

Find the number of boomerangs. You may assume that n will be at most 500 and coordinates of points are all in the range [-10000, 10000] (inclusive).

Example: