Right Triangle Characters Pattern in Two Different Programming Languages Golang And Javascript
Patterns are most common question in interview, Because most of the Developer asks candidates to write code which prints specific pattern, to check if candidate have the logical mind or not , Is he understands the flow of the loop. It defines your understanding the flow of code mostly Loops So in this article we're about to cover up a right triangle Character pattern in which we're not going to print any star we're about to print Alphabates from A-Z. So we're going to cover up this in Golang and Javascript, So let's start Writing Code.
1. Flow of the Pattern
Let's Discuss first how we're going to write logic for this and how many loops we need and how we're going to print Alphabates. A. First we needed temp variable which holds the incremented number so we can use that to print B. Then We have to declare another variable which is int and we will using this for rows, Means how many rows or we can say our main loops dead end. C. At step three we have to create two loops which is connect, Inner loop going to iterate over from i+i means if our main loops start from 65 so next loop will going to start from 66 till variable i D. Important part, we have to convert our number to character(Alphabate) so we can use it to print Alphabate triangle.
2. Golang
We are starting writing pattern code for golang first. For Converting Int to character in golang we're going to use the fmt package's Printf function and the specifier will be using %c, It can convert number into character. Bonus: There is another function as well you can use to convert number into character which is Sprintf and also use the %c specifier to convert it.
3. Javascript
Working on patterns with javascript can be easy for everyone but when it comes to print charatcers it can't be easy. So How do we are going to convert int to character in javasript? Well there is a simple answer by using the String Module. String Module have fromCharCode function which takes only one argument which is the int and returns back the character of that number. Below is the code for pattern.
Labels: Golang, javascript, patterns
0 Comments:
Post a Comment
If have any queries lemme know
Subscribe to Post Comments [Atom]
<< Home