We mainly use JavaScript to create dynamic web applications. This kind of scripting language makes a web page look interactive. JavaScript significantly adds some logic to our website. As we mentioned, the user can check whether the background image is loaded. Web developers can understand that the page is loaded correctly and that the background image is displayed properly. To check whether the background image is loaded as directed by the web developers on the web page user can use the image object. We can access this object's properties and methods related to an image, and we can apply ... Read More
Keywords are reserved words used to perform some internal process or represent predefined actions. It is not allowed to use these keywords as a variable name, constant name, or identifier. Swift support approx 101 keywords. For example, ‘var’ is a keyword but ‘hey’ is not a keyword. Here, we will learn how to write a swift program to check whether a given string is a keyword. Algorithm Step 1 − Create an array of string types to store all the keywords supported by Swift. Step 2 − Create a function to check if the given string is a ... Read More
A palindrome array is an array that remains the same when its elements are reversed we can also say that the elements of a palindrome array remain the same even if we read it from backward or forward. For example, [1, 9, 10, 9, 1] is a palindrome array whereas [3, 5, 7, 8, 3, 2, 1] is not a palindrome array. In this article, we are going to learn different methods of finding whether the given array is a palindrome or not suing Swift programming language. Algorithm Step 1 − Create a function. Step 2 − Reverse the ... Read More
An array is used to store elements of the same data type in an order whereas a set is used to store distinct elements of the same data type without any definite order. To convert Array into set we use Set() initialiser. The resultant set contains the same elements as the original array but with no order and no duplicate elements. In this article, we will learn how to convert Array to Set using Swift programming language. Algorithm Step 1 − Create an array of integer type. Step 2 − Print the array. Step 3 − Convert array into ... Read More
1’s complement of a binary number is the invert of the given number. For example, we have a number = 10101011, so the one’s complement is 01010100. Here we using the following two methods to find one’s complement − Replacing 1s with 0s and 0s with 1s Using XOR In this article, we will learn how to write a swift program to find the 1’s complement of the given number. Method 1: Replacing 1s with 0s and 0s with 1s It is the smallest method to find ons complement of the given number. Here we simply convert the given number ... Read More
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
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
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
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
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