Janice Alecha

Posted on

# The Beginners Approach to Algorithm.

In computer programming terms, an algorithm is a set of well-defined instructions to solve a particular problem.

Why are Algorithms Important to Understand?

Algorithmic thinking, or the ability to define clear steps to solve a problem, is crucial in many different fields. Even if weโre not conscious of it, we use algorithms and algorithmic thinking all the time. Algorithmic thinking allows students to break down problems and conceptualize solutions in terms of discrete steps. Being able to understand and implement an algorithm requires students to practice structured thinking and reasoning abilities.
This article originally appeared on junilearning.com

What better way to practice algorithmic problem solving than to find solutions to check Palindrome in JavaScript.

First off, what is a Palindrome?
A palindrome is a word, number, phrase, or another sequence of characters that can be read backward and forwards, like a kayak or racecar.

Instruction:

Write a function isPalindrome that will receive one argument, a string. Your function should return true if the string is a palindrome (that is, if it reads the same forwards and backwards, like "kayak" or "racecar"), and return false if it is not a palindrome.

In our exercises, we were given recommended steps as follows:

• Rewrite The Problem in Your Own Words

I love this part since we're able to write the problem the way we understand it.
/I need to make an isPalindrome function() that returns either true or false. When the input string is the same forwards and backwards, I should return true. That means that if the input string is the same after I reverse it, I should return true. For instance, "kayak" in reverse is also "kayak", and "racecar" in reverse is also "racecar", so my solution should return true for these cases. "hello" in reverse is "olleh", so my solution should return false for this case./

• Write Your Own Test Cases

This to me is identifying what input your code should handle and what output you expect to return. Like a trial and error. This way will help you build the model to solve the problem.

Examples From Our Lecture:

• Pseudocode

How do you effectively write a Pseudocode and What are its advantages? So many questions.

Defining Pseudocode

Pseudocode is a simple way of writing programming code in English. Pseudocode is not an actual programming language. It uses short phrases to write code for programs before you create them in a specific language. Once you know what the program is about and how it will function, then you can use pseudocode to create statements to achieve the required results for your program.-Alisa Perry

It is like writing your code on your terms and rules in short statements. I'm learning slowly but surely.

• CODE

Using Built-In JavaScript Methods:

The split() method is a built-in method provided by JavaScript. This method splits the string into a list of substrings.

The reverse() method on the other hand is a built-in method provided by JavaScript. This method reverses an original array instead.

Lastly, The join() method is a built-in method provided by JavaScript. This method creates and returns a new string by concatenating all the elements in an array (or array-like object), separated by commas or a specified delimiter string.

• Make It Clean And Readable

I'd say make your solution organized and simple as much as possible and prevent it from being redundant 'Don't Repeat Yourself. Try to develop a basic structure and strive for readability.

• OPTIMIZE

It means coming up with a new way to reverse a string that involves fewer steps or coming up with another solution that doesn't involve reversing a string. For instance, using for loop.

Conclusion:

I still have a lot to learn and a long way to go. The first thing I need to get better at is understanding the fundamentals and data structures. Read books and watch tutorials. Be more resourceful and have fun practicing algorithms using the steps on Coderbyte and HackerRank or simply write them down on my notepad. One step at a time.

DEV Community

## 11 Tips That Make You a Better Typescript Programmer

### 1 Think in {Set}

Type is an everyday concept to programmers, but itโs surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

### #2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

### #3 Use discriminated union instead of optional fields

...

Read the whole post now!