koalamango / js-algorithms

✨ A collection of algorithms written in JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Common Algorithms in JavaScript

What's an algorithm?

An algorithm is a set of instruction to solve problems.

Still confused? Watch the video of Professor David J. Malan explains how algorithms can be used in seemingly simple situations and also complex ones.

List of common algorithms

Fizz-Buzz is a group word game for children to teach them about division. Players take turns to count incrementally, replacing any multiple of three with the word "fizz", and any multiple of five with the word "buzz".

You are given an array of n integers and a number k. Determine whether there is a pair of elements in the array that sums to exactly k. For example, given the array [1, 3, 7] and k = 8, the answer is "yes" but given k = 6 the answer is "no"

The harmless ransom note is simply a note made of words cut out from a magazine text.

You have been given two strings. You have to find out whether you can make up the first string with the words present in the second string.

A palindrome is a word, phrase, number or sequence of words that reads the same backward as forward. Punctuation and spaces between the words or lettering is allowed.

Caesar cipher is to replace each plaintext letter with a different one a fixed number of places down the alphabet. The cipher illustrated here uses a left shift of three, so that (for example) each occurrence of E in the plaintext becomes B in the ciphertext.

Reverse the string without using array.prototype.reverse().

Reverse the order of the elements of an array.

Calculate the mean, median, or mode of a data set!

The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, . . . Each subsequent number is the sum of the previous two.

Write a function to return an n element in Fibonacci sequence

In mathematics, the sieve of Eratosthenes is an ancient algorithm for finding all prime numbers up to any given limit. It does so by iteratively marking as composite (i.e., not prime) the multiples of each prime, starting with the first prime number, 2.

Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number.

Given an array of stock prices over time, need to figure out the best buy and sell price so that we get the maximum profit. The selling should occur after buying of the stock.

  • Plurality (winner take all)

In the plurality vote, every voter gets to vote for one candidate. At the end of the election, whichever candidate has the greatest number of votes is declared the winner of the election.

  • Runoff

In a ranked-choice system, voters can vote for more than one candidate. Instead of just voting for their top choice, they can rank the candidates in order of preference.

  • Readability
  • Liner Search
  • Binary Search
  • Bubble Sort
  • Selection Sort
  • Insertion Sort
  • Recursion
  • Merge Sort

About

✨ A collection of algorithms written in JavaScript


Languages

Language:JavaScript 100.0%