Server Side Programming Articles

Page 1683 of 2109

Golang program to get the first and last element from a slice

Akhil Sharma
Akhil Sharma
Updated on 17-Jan-2023 2K+ Views

In this tutorial, we will discuss how to obtain the first and last element from a slice. A slice is a dynamic-sequence that stores elements of a similar type. It is similar to array but it can be resized whereas an array is of fixed range. Let’s understand the concept using some examples. Method 1: Using integer values In this method, we will use integer values to get the first and last element from a slice. The output will be printed on the screen using fmt.Println() function. Let’s go through the example to understand how it can be done. Algorithm ...

Read More

Golang program to compare elements in two slices

Akhil Sharma
Akhil Sharma
Updated on 17-Jan-2023 3K+ Views

In this tutorial, we will learn how to compare elements in two slices. In slices a simple equality comparison is not possible so the slices are compared with their lengths and the elements present in the loop. The output will be printed in the form of Boolean value on the console with the help of fmt.Println() function. Let’s see how to execute this with the help of an example. Method 1: Using a user-defined function In this method, we will compare elements in two slices using an external function and, in that function, we will set some conditions, if the ...

Read More

Golang program to replace elements in a slice

Akhil Sharma
Akhil Sharma
Updated on 17-Jan-2023 4K+ Views

In this tutorial, , we will grasp how to replace elements in a slice using different set of examples. A slice is a dynamic array which means that its value is not fixed like array. The output will be printed on the screen using fmt.Println() function. Let’s see how it can be implemented with crystal-clear examples. Method 1: Using built-in copy function In this method, we will use the built-in function copy to replace elements in slice which means at the place of original element and new element will be placed. The built-in functions shorten the code and easily solve ...

Read More

Golang program to print a slice

Akhil Sharma
Akhil Sharma
Updated on 17-Jan-2023 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
Akhil Sharma
Updated on 17-Jan-2023 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 remove an element from a slice

Akhil Sharma
Akhil Sharma
Updated on 17-Jan-2023 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 add elements to a slice

Akhil Sharma
Akhil Sharma
Updated on 17-Jan-2023 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

How to create a Function with Arguments but without a return value in Golang?

Aman Sharma
Aman Sharma
Updated on 17-Jan-2023 425 Views

This tutorial will teach us how to create a function with arguments but without a return value. This tutorial involves a gist about the function, and syntax for the function with argument and without return type in Golang, then last we will see two different examples of a function with arguments but without a return type. In the first example, we are going to print the argument passed in the function with the respective statement. In the other example, we are going to add the numbers passed as arguments and print the sum in the same function. Function with argument ...

Read More

How to use interface with class in TypeScript?

Shubham Vora
Shubham Vora
Updated on 16-Jan-2023 2K+ Views

In TypeScript, classes are the template that defines the variables and methods. We can use class templates to create objects, which means the class is the reusable component in object-oriented programming, and we can reuse it by creating its object. We can use the ‘interface’ keyword to define the interfaces in TypeScript. The interface contains the class structure. The interface is similar to abstract classes we define in other programming languages, such as Java and C++. It contains only the declaration of variables with their type and method with its return type and parameter types. Classes define the interface's methods ...

Read More

How to Select Important Variables from Dataset?

Parth Shukla
Parth Shukla
Updated on 16-Jan-2023 2K+ Views

Introduction In machine learning, the data features are one of the parameters which affect the model's performance most. The data's features or variables should be informative and good enough to feed it to the machine learning algorithm, as it is noted that the model can perform best if even less amount of data is provided of good quality. The traditional machine learning algorithm performs better as it is fed with more data. Still, after some value or the quantity of the data, the model's performance becomes constant and does not increase. This is the point where the selection of the ...

Read More
Showing 16821–16830 of 21,090 articles
Advertisements