Found 33676 Articles for Programming

Golang program to print a slice

Akhil Sharma
Updated on 17-Jan-2023 12:25:09

3K+ Views

In this tutorial, we will learn different methods to print a slice. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Let’s understand this basic concept using different set of examples and algorithms based upon them. Method 1: Using make function In this method, we will create a slice with the help of make function and ... Read More

Golang program to reverse a slice

Akhil Sharma
Updated on 17-Jan-2023 12:19:09

4K+ Views

In this tutorial, we will learn how to reverse a slice using variety of examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Let’s go through the example to understand things. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of ... Read More

Golang program to search an element in the slice

Akhil Sharma
Updated on 17-Jan-2023 13:08:47

4K+ Views

In this tutorial, we will grasp how to search an element in slice using different set of examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument ... Read More

Golang program to remove an element from a slice

Akhil Sharma
Updated on 17-Jan-2023 12:03:48

1K+ Views

In this tutorial, we will learn how to remove an element from a slice using variety of examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Let’s go through the example to understand things. Syntax func copy(dst, str[] type) int The copy function in go language is used to copy the values of ... Read More

Golang program to find the largest element in a slice

Akhil Sharma
Updated on 17-Jan-2023 11:57:09

1K+ Views

In this tutorial, we will inculcate how to find the largest element in a slice using some examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Let’s go through the example to understand things. Method 1: Using a user-defined function and append() function In this method, we will see how to find the largest element ... Read More

Golang program to add elements to a slice

Akhil Sharma
Updated on 17-Jan-2023 11:42:47

1K+ Views

In this tutorial, we will learn how to add elements to a slice using different examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Let’s go through the example to understand things. Method 1: Using append function with strings In this method, we will use append function to add string elements to the slice. ... Read More

Explain the purpose of never type in TypeScript

Rushi Javiya
Updated on 17-Jan-2023 10:13:24

2K+ Views

TypeScript is a type-strict language in which we need to define the type for every variable. Also, we need to define the return type of the function and the types of parameters of the function. The never is also one of type in TypeScript like other data types such as string, number, boolean, symbol, etc. We can use the ‘never’ keyword to make a variable of never type. Users can use the never type when they are sure about any situation that will never occur. For example, we can use the never as a return type when we are sure ... Read More

Explain the different variants of for loop in TypeScript

Rushi Javiya
Updated on 17-Jan-2023 10:04:21

344 Views

In any programming language, we use the loops to execute the same code block repeatedly or multiple times. The loops allow us to write less code to execute the same code block many times. The for loop is one of the loops in TypeScript. As given below, there are also three different sub-types of the for loop in TypeScript. Normal for loop for-of loop for-in loop We will learn about all variants of the for loop in this TypeScript tutorial. Also, we will learn how each type of for loop is different from others. Introduction to normal for ... Read More

Explain the Tuple Types in TypeScript

Rushi Javiya
Updated on 17-Jan-2023 10:01:18

329 Views

We will learn about the tuple types in TypeScript. In JavaScript, an array can contain elements of different data types. Still, as TypeScript is a superset of JavaScript and type-strict language, a TypeScript array can contain only single types of elements. So, the tuple allows us to store elements of the different data types in the TypeScript array. Also, when we store elements inside the tuple, the order of elements is important; Otherwise, the TypeScript compiler can generate an error while compiling the code. Syntax You can follow the syntax below to define the tuples in TypeScript. let sample_tuple: [string, ... Read More

Explain the symbol type in TypeScript

Rushi Javiya
Updated on 17-Jan-2023 09:58:20

6K+ Views

The Symbol is introduced in the last main revision of JavaScript, ES6. The Symbol is a data type. As we use the number, string, or Boolean to create the variables of different data-type, we can use the symbol type to create the Symbol. Using the symbol types has many benefits as it provides more features than other data types. In this tutorial, we will learn about the basics of the Symbol and its different uses of the Symbol. Syntax Users can follow the syntax below to create a variable of symbol data type. let test_symbol = Symbol(); let key_symbol = ... Read More

Advertisements