Found 26504 Articles for Server Side Programming

Golang Program to Calculate the intersection of two Slices

Akhil Sharma
Updated on 13-Feb-2023 16:01:20

2K+ Views

In Golang, 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 is the array to which we wish to add the values followed by the values to add. ... Read More

Golang program to calculate union of two slices

Akhil Sharma
Updated on 13-Feb-2023 15:59:54

2K+ Views

In golang, a slice is known as dynamic array where it's value is not fixed and can be changed. It is more efficient and faster compared to simple arrays. In this article, we are going to learn how to calculate a union of two different slices using examples. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an ... Read More

Golang program to split a slice into two halves

Akhil Sharma
Updated on 13-Feb-2023 15:58:37

3K+ Views

A slice can also be called as a dynamic array as it's value is dynamic whereas normal array is static. This makes slice more efficient and faster. They are passed by reference instead by value. Let us learn how to split a slice into two halves using Golang program. 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 is the array to which we wish to add the values followed by the values to add. The function then returns the final ... Read More

Golang program to merge two slices

Akhil Sharma
Updated on 13-Feb-2023 15:57:29

6K+ Views

In Golang, 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 is the array to which we wish to add the values followed by the values to add. ... Read More

Swift Program to Show Overloading of Methods in Class

Ankita Saini
Updated on 08-Feb-2023 20:07:01

255 Views

Method overloading is a technique that allows us to create multiple methods of same name within a single class but with different parameter types or different number of parameters. The specific method that is called is determined by the types or number of arguments passed to it at the time of the method call. For example − class Book { // Methods func Author(){} func Author(x: Int)->Int{} func Author(x: String)->String{} func Author(a: Int, b: String)->Int{} } Here, the class Book has four overloaded methods. ... Read More

Swift Program to Iterate Over an Array

Ankita Saini
Updated on 08-Feb-2023 20:09:08

4K+ Views

An array is used to store elements of same data type in an order. In this article, we will learn how to write a swift program to iterate over an array. Here we use the following methods to iterate through each element of the array − Using for-in loop Using forEach() function Using while loop Using enumerated() function Method 1: Using for-in loop To iterate over an array we can use for-in loop. Syntax for value in Sequence { // statement } Here, the value parameter contains an element of the array during the ... Read More

Swift Program to insert multiple elements into the array from the specified index

Ankita Saini
Updated on 08-Feb-2023 20:14:53

1K+ Views

An array is used to store elements of same data type. In this article, we will learn how to write a swift program to insert multiple elements into the array from the specified index. Here we use the following methods to insert multiple elements into the array from the specified index − Using Index Using insert(contentsOf:at:) function Method 1: Using Index Here we use square brackets[] along with rang operators to insert multiple elements into the array at the specified index. Algorithm Step 1 − Create an array of integer. Step 2 − Create another array ... Read More

Swift Program to get array elements after N elements

Ankita Saini
Updated on 08-Feb-2023 20:15:22

472 Views

An array is used to store elements of same data type in an order. So now we extract the array elements after N elements. For example − Array : [2, 4, 5, 6, 7, 9] N = 3 ResultArray = [6, 7, 9] In this article, we will learn how to write a swift program to get array elements after N elements. Algorithm Step 1 − Create function. Step 2 − Create a new array using Array() initializer that containing elements after N elements. Step 3 − Return the resultant array. Step 4 − Create an array and a ... Read More

Swift Program to find the index of the first occurrence of the specified item in the array

Ankita Saini
Updated on 08-Feb-2023 20:16:08

847 Views

An array is used to store elements of the same data type in order. Here we will learn how to write a swift program to find the index of the first occurrence of the specified item in the array. To achieve that we are going to use the following methods to find the index of the first occurrence of the array element − Using user-defined function Using firstIndex() function Method 1: Using user-defined function To find the index of the first occurrence of the specified element in the array we create a function which iterate through each elements ... Read More

Swift Program to find the given number is strong or not

Ankita Saini
Updated on 08-Feb-2023 20:16:57

262 Views

A strong number is a special number in which the sum of the factorial of its digit is equal to the number itself. For example − Number = 345 345! = 3! + 4! + 5! = 6 + 24 + 120 = 150 Here 345 is not a strong number because the sum of the factorial of its digit is not equal to the number itself. Number = 145 145! = 1! + 4! + 5! = 1 + 24 + 120 = 145 Here 145 is a strong number because the sum of the factorial of its ... Read More

Advertisements