A smart contract is nothing but a piece of code (computer program) that uses distributed ledger technology to follow the core principle of blockchain i.e distributed, trustless, and transparency. It is an immutable (Non- changeable) digital file having data and predefined code with an address on the network. That predefined code of conditions defined in the smart contract should be met and verified on specific event occurrences for smooth execution. It follows the logic of If/else and do/while. It is used to automate the execution of programs to save time without using intermediaries. It has various advantages over the conventional ... Read More
The given task is to sort an array of objects by using string property value in JavaScript. Assume there is an array of objects and we need to sort those elements by using the string property. In this below scenario, we are sorting array of objects by "company" property. const array = [ {Company: 'Oneplus', Manufacturing: 'China'}, {Company: 'Samsung', Manufacturing: 'South korea'}, {Company: 'Nothing', Manufacturing: 'India'} ]; Output = // it sorted the array of objects by "company" property. [ {"Company":"Nothing", "Manufacturing":"India"}, {"Company":"Oneplus", "Manufacturing":"China"}, ... Read More
The given task is to replace the elements in an array with elements of another array. Input-Output Scenario Let’s look into some input-output scenarios. Consider there are there two arrays with elements in it. The first array is having more elements than the second array and we are replacing a part of elements in the first array with the elements from second array. Array1 = [1, 3, 5, 7, 2, 4]; Array2 = [3, 6]; Output = [3, 6, 5, 7, 2, 4] // elements got replaced Let’s consider another scenario, where the elements in the first array are ... Read More
Today In the computer industry, testing becomes more inclined to better quality and optimization, without any delay in operation and execution of business requirements. Developing good quality products and services without incorporating higher costs into their production becomes a tedious task. And this becomes more problematic when we are in blockchain technology where everything is linked to crypto transactions even for small amounts of transactions. The testing environment gives us a better solution to pre-production in blockchain development where we can use Test Tokens, also known asTest Faucets for our smart contract deployment. These test Faucets have no value in ... Read More
In this article, the given task is to get the best way of finding the length of a JSON object in JavaScript. Input-Output Scenario Let’s look into this input-output scenario. Consider there is an object with some keys and values in it. we need to get the length of the object. const MyObj = { Name: "Mike", Age: 34 }; document.write(Object.keys(MyObj).length); // Output: 2 Using Object.keys() The Object.keys() method will return the output in form of array of a given object’s own enumerable properties names. It will return the output of keys ... Read More
The given task is to remove the negative values from the array. Input-Output Scenario Let’s look into input output scenarios. Consider there is an array and it is having both negative and positive integer values. We need to remove the negative values from the array and return the array. Input = [-2, 5, -7, 32, 78, -32]; Output = [5, 32, 78] Now let’s assume there are no negatives integer values in the array. so, the array will be returned in the same order. Input = [56, 43, 12, 67, 69, 34]; Output = [56, 43, 12, 67, 69, ... Read More
The given task is to perform joining arrays to form strings in JavaScript. Input-Output Scenario Let’s look into some input-output scenarios. Consider there is an array having some elements in it and we are trying to join that array to form the string. Input = [32, 45, 65, 12, 07, 55]; Output = 32, 45, 65, 12, 07, 55 //String Let’s look into another scenario, where we are having two arrays and we are trying to join those two arrays and form a string. Array1 = [123, 453, 656, 654, 125, 757]; Array2 = ["Hello", "honey", "bunny"]; Output = ... Read More
The task is to match a specific word or character which is in regex with a string. The regex (regular expressions) is a pattern that is used to match character combinations in strings. Here we include the test(), match(), and matchAll() methods to match the following word in regex. We have some boundary-type assertions, in which we have used \b. Consider a sentence – “mickey is holding mic.” Using regex - \bmic\b will match the word mic but not the word mic in mickey. It is a word boundary. Another assertion is (g), It is a global search flag. Consider ... Read More
The given task is to reorder an array in JavaScript. We can reorder the elements in the array by using the following methods. One of the ways to achieve the above task is b using sort() method. The sort() is an in-built method in JavaScript, which sorts the alphabetic elements. By default, it sorts in ascending order. Example Following is the example where the array got reordered in ascending order − const States = ["Telangana", "Uttar Pradesh", "Karnataka", "Kerala", ... Read More
The Hex (Hexadecimal) code is a six-digit code and a three-byte hexadecimal number that is used to represent the colors. These three bytes represent RGB which means the amount of red, green, and blue in a particular shade of a color. Each byte will represent a number in the range 00 to FF (Hexadecimal notation) or 0 to 255 in decimal notation. This indicates the intensity of each of the color components from 0 to 255. The following are the functions to be used for generating random hex codes − Math.random() is used to get the number randomly in the ... Read More