Null Check and Insertion Rule in DB2 Table

Mandalika
Updated on 14-Sep-2020 14:06:49

751 Views

Null in DB2 is defined as nothing. It is an unknown value. If we want to restrict NULL value in any column then the column should be defined with the “NOT NULL” parameter in CREATE TABLE.The “NOT NULL” will force the user to enter a value for the column. However, if we do not want to give any value for this column we can also place a “WITH DEFAULT” parameter which will allow DB2 to place the default value in case the user has not provided any value for the “NOT NULL” column.For example, if we have a column INVOICE_ID ... Read More

Pronic Numbers in JavaScript

AmitDiwan
Updated on 14-Sep-2020 14:05:35

262 Views

A Pronic number is a number which is the product of two consecutive integers, that is, a number of the form n(n + 1).We are required to write a JavaScript function that takes in a number and returns true if it is a Pronic number otherwise returns falseLet’s write the code for this function −Exampleconst num = 90; const isPronic = num => {    let nearestSqrt = Math.floor(Math.sqrt(num)) - 1;    while(nearestSqrt * (nearestSqrt + 1)

Inverting Signs in Array JavaScript

AmitDiwan
Updated on 14-Sep-2020 14:03:41

599 Views

We are required to write a JavaScript function that takes in an array of positive as well as negative Numbers and changes the positive numbers to corresponding negative numbers and the negative numbers to corresponding positive numbers in place.Let’s write the code for this function −ExampleFollowing is the code −const arr = [12, 5, 3, -1, 54, -43, -2, 34, -1, 4, -4]; const changeSign = arr => {    arr.forEach((el, ind) => {       arr[ind] *= -1;    }); }; changeSign(arr); console.log(arr);OutputFollowing is the output in the console −[    -12, -5,  -3, 1, -54,    43,  2, -34, 1,  -4,    4 ]

Finding if Three Points are Collinear in JavaScript

AmitDiwan
Updated on 14-Sep-2020 14:01:39

662 Views

Collinear PointsThree or more points that lie on the same straight line are called collinear points.And three points lie on the same if the slope of all three pairs of lines formed by them is equal.Consider, for example, three arbitrary points A, B and C on a 2-D plane, they will be collinear if −slope of AB = slope of BC = slope of acceptsSlope of a line −The slope of a line is generally given by the tangent of the angle it makes with the positive direction of x-axis.Alternatively, if we have two points that lie on the line, ... Read More

Replace Words of a String in JavaScript

AmitDiwan
Updated on 14-Sep-2020 13:59:49

400 Views

We are required to write a JavaScript function that takes in a string and replaces the adjacent words of that string.For example: If the input string is −const str = "This is a sample string only";Then the output should be −"is This sample a only string"Let’s write the code for this function −ExampleFollowing is the code −const str = "This is a sample string only"; const replaceWords = str => {    return str.split(" ").reduce((acc, val, ind, arr) => {       if(ind % 2 === 1){          return acc;       }     ... Read More

Return Two Numbers Whose Sum is N and Product M in JavaScript

AmitDiwan
Updated on 14-Sep-2020 13:57:55

222 Views

We are required to write a JavaScript function that takes in two numbers, say m and n and returns two numbers whose sum is n and product is m. If there exist no such numbers, then our function should return falseLet’s write the code for this function −Exampleconst perfectNumbers = (sum, prod) => {    for(let i = 0; i < (sum / 2); i++){       if(i * (sum-i) !== prod){          continue;       };       return [i, (sum-i)];    };    return false; }; // 12 12 are not two distinct numbers console.log(perfectNumbers(24, 144)); console.log(perfectNumbers(14, 45)); console.log(perfectNumbers(21, 98));OutputFollowing is the output in the console −false [ 5, 9 ] [ 7, 14 ]

Cascade Rule for Foreign Key in Database

Mandalika
Updated on 14-Sep-2020 13:57:08

3K+ Views

The foreign key is used to establish a referential constraint between the child table(in which column is defined as foreign key) and parent table (in which foreign key of the child table becomes primary key). For example if we have an ORDER table in which foreign key is defined as TRANSACTION_ID. This foreign key will refer to the TRANSACTION_ID column of TRANSACTIONS table. In this TRANSACTIONS table, TRANSACTION_ID will be the primary key. The parent table here is TRANSACTIONS table while the child table here is ORDERS table.The CASCADE rule of the foreign key states that when any entry is ... Read More

Delete Duplicate Elements Based on First Letter in JavaScript

AmitDiwan
Updated on 14-Sep-2020 13:55:57

152 Views

We are required to write a JavaScript function that takes in array of strings and delete every one of the two string that start with the same letter.For example, If the actual array is −const arr = ['Apple', 'Jack' , 'Army', 'Car', 'Jason'];Then, we have to keep only one string in the array, so one of the two strings starting with A should get deleted. In the same way, the logic follows for the letter J in the above array.Let’s write the code for this function −Exampleconst arr = ['Apple', 'Jack' , 'Army', 'Car', 'Jason']; const delelteSameLetterWord = arr => ... Read More

Definition and Usage of Alternate Key in a DB2 Table

Mandalika
Updated on 14-Sep-2020 13:52:07

707 Views

The DB2 table contains a number of columns whose value will remain unique in the entire table. Among these multiple columns only one column is selected as the primary key and the remaining keys are known as candidate keys.We can declare any candidate key as an alternate key. Which means that the value of this key cannot take duplicate value, however unlike primary key the primary index is not built on the alternate key.We can define alternate key while defining any table using a UNIQUE keyword. For example, if we want to make TRANSACTION_ID as an alternate key then−CREATE TABLE ... Read More

Sum Negative and Positive Digits in JavaScript

AmitDiwan
Updated on 14-Sep-2020 13:51:46

2K+ Views

We are required to write a JavaScript function that takes in a negative integer and returns the sum of its digitsFor example −-234 --> -2 + 3 + 4 = 5 -54  --> -5 + 4 = -1Let’s write the code for this function −ExampleFollowing is the code −const num = -4345; const sumNum = num => {    return String(num).split("").reduce((acc, val, ind) => {       if(ind === 0){          return acc;       }       if(ind === 1){          acc -= +val;          return acc;       };       acc += +val;       return acc;    }, 0); }; console.log(sumNum(num));OutputFollowing is the output in the console −8

Advertisements