/Algo-Checkpoint

Working on updating my Algorithms understanding

Primary LanguageJavaScript

Algo-Checkpoint

This repository contains an algorithm that performs various operations on a given sentence.

Algorithm Description

The algorithm takes a sentence as input and performs the following operations:

  1. Counts the number of words in the sentence.
  2. Counts the total number of characters in the sentence.
  3. Counts the number of vowels in the sentence.

The algorithm uses a for loop to iterate over each character in the sentence. If the character is a space, it increments the word count. If the character is not an empty string, it increments the character count. If the character is a vowel (a, e, i, o, u), it increments the vowel count.

Variables

  • sentence: A string that represents the sentence to be analyzed.
  • sentence_length: An integer that stores the total number of characters in the sentence.
  • vowels: An integer that stores the total number of vowels in the sentence.
  • word_length: An integer that stores the total number of words in the sentence.
  • vowels: A string that contains all the vowel characters.

Usage

To use this algorithm, you need to provide a sentence as input. The algorithm will then calculate and return the number of words, total characters, and vowels in the sentence.

##SECOND CHECKPOINT

Insertion Sort Function

This repository also includes a function called insertionSort that sorts an array of numbers in ascending order.

Function Description

The insertionSort function takes an array of numbers as input and sorts the numbers in ascending order using the insertion sort algorithm. The function iterates over each element in the array, starting from the second element. For each element, it finds the correct position in the sorted part of the array and inserts the element at that position.

Variables

  • arr: An array of numbers that needs to be sorted.
  • current: The current element that needs to be inserted into the sorted part of the array.
  • j: An index used to iterate over the sorted part of the array.

Usage

To use this function, you need to provide an array of numbers as input. The function will then sort the numbers and return the sorted array.

Here is an example of how to use the function: