Swap Variables with Destructuring in JavaScript

vineeth.mariserla
Updated on 30-Jun-2020 15:46:43

233 Views

Swapping variables has become very easy with destructuring. In contemporary javascript swapping takes place by using another variable. It may not be hectic but it is lengthy. But in modern javascript there is no need for the third variable. Let's discuss it in detail.Example-1In the following example, swapping has done using another variable called "temp". Therefore the code got lengthier. Live Demo           var a = "Sachin";       var b = "Tendulkar";       document.write("Before swapping-"+ " "+ a + " " +b);       var tmp = a;       a = b; ... Read More

Importance of str.padStart() Method in JavaScript

vineeth.mariserla
Updated on 30-Jun-2020 15:31:18

190 Views

We can attach two strings using the concat() method. But if we need to attach a specific string at the starting of the first string then the easiest way is string.padStart(). This method not only adds the second string at the start of the first string but also looks after the number of characters to be added. It basically takes two parameters one is the length and the other is second string. The method string.padStart() add the second string to the first based on the length provided to it.syntaxstring.padStart(length, "string");It takes the length as the parameter to concise the resulted string to those ... Read More

C Program to Find Decagonal Number

karthikeya Boyini
Updated on 30-Jun-2020 15:28:18

113 Views

A decagonal number is a figurate that was derived using the concept of triangular numbers and square numbers. This extension of number pattern is created using non-rotationally symmetrical numbers. This nested decagon oriented number is given by the number of dots in the number of nested decagons that are created. For example, for 3rd decagonal number 3 decagonal figures are nest each with iX time the number of sides in the decagon. As shown in figure −Side in 1st Outer figure = 30 Side in 2nd Outer figure = 20 Side in inner figure = 10 Sides common in all = 6+2 Total = 30+20+10-(6+2) ... Read More

Extend Interfaces in Java

Maruthi Krishna
Updated on 30-Jun-2020 15:17:30

1K+ Views

An interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Just like classes you can extend one interface from another using the extends keyword as shown below −interface ArithmeticCalculations{    public abstract int addition(int a, int b);    public abstract int subtraction(int a, int b); } interface MathCalculations extends ArithmeticCalculations{    public abstract double squareRoot(int a);    public abstract double powerOf(int a, int b); }But, when you implement the sub-class you need to provide body for the abstract methods in both interfaces.ExampleIn the following example we have created two interfaces ... Read More

Add 1 to a Given Number

karthikeya Boyini
Updated on 30-Jun-2020 15:14:54

1K+ Views

A program to add 1 to a given number increments the value of the variable by 1 . This is general used in counters.There are 2 methods to increase that can be used to increase a given number by 1 −Simple adding of one to the number and reassigning it to the variable.Using increment operator in the program.Method 1 − using reassignment methodThis method takes the variable, add 1 to it and then reassigns its value.Example Code Live Demo#include int main(void) {    int n = 12;    printf("The initial value of number n is %d ", n);    n ... Read More

Swap Data Between Two Columns in MySQL

Sharon Christine
Updated on 30-Jun-2020 15:06:56

1K+ Views

To swap data between two columns in MySQL, use the concept of variable. Let us first create a table. Here, we will swap Name1 with Name2 −mysql> create table DemoTable -> ( -> Name1 varchar(100), -> Name2 varchar(100) -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John Smith', 'Chris Brown'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('David Miller', 'Jone Doe'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce ... Read More

MySQL Stored Procedure to Return a Column Value

Sharon Christine
Updated on 30-Jun-2020 15:05:27

994 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> Score int    -> ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1, 858858686); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(2, 9900554); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(3, 646565667); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+------+-----------+ | Id ... Read More

Add Dots to String with More Than 10 Words in MySQL

karthikeya Boyini
Updated on 30-Jun-2020 15:04:24

335 Views

For this, use CASE statement. Let us first create a table −mysql> create table DemoTable -> ( -> Title text -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('My name is John and this is my first tutorial on MySQL'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('This is Carol and I work on MongoDB'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+--------------------------------------------------------+ | Title ... Read More

Insert Row with Only Default Values in MySQL

karthikeya Boyini
Updated on 30-Jun-2020 15:03:29

2K+ Views

Use DEFAULT keyword at the time of table creation and it will insert default value whenever you do not provide the value for that column.Let us first create a table. Here, for ClientAge, we have set the default 24:Let us first create a table. Here, for ClientAge, we have set the default 24 −mysql> create table DemoTable    -> (    -> ClientId int AUTO_INCREMENT PRIMARY KEY,    -> ClientName varchar(100),    -> ClientAge int DEFAULT 24    -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command. For values which are not ... Read More

Increase Database Field Value by Specified Percentage in MySQL

karthikeya Boyini
Updated on 30-Jun-2020 15:01:18

407 Views

Let us first create a table −mysql> create table DemoTable -> ( -> Amount int -> ); Query OK, 0 rows affected (0.99 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(200); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(500); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+--------+ | Amount | +--------+ | 100 | | 200 ... Read More

Advertisements