Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Front End Technology Articles
Page 475 of 652
crypto.createDiffieHellman() Method in Node.js
The above method creates a DiffieHellman key exchange object with the help of the supplied prime value and an optional specific generator. The generator argument can hold either a string, number or Buffer value. Default value for generator is 2.Syntaxcrypto.createDiffieHelmmanGroup(prime, [primeEncoding], [generator], [generatorEncoding]ParametersThe above parameters are described as below −prime – The number of prime bits that will be generated. Input value is of type number.primeEncoding – This parameter defines the encoding of the prime string. Possible input types are: string, buffer, TypedArray and DataView.generator – Generator for generating the exchange key object. Default value: 2.generatorEncoding – This parameter defines the generator string encoding.ExampleCreate ...
Read MoreLogging in Node.js
Logging is a very essential part in any application whether it is made in Node.js or any other programming languages. Logging helps us to detect weird behaviours of an application along with real-time errors and exceptions. One should definitely put logical logs in their application. These logs help the user to identify any mistakes and resolve it on urgent basis.There are 5 different log levels which are present at the moment with the user. These log levels are used to define different kinds of logs and helps the user to identify different scenarios. The log levels must be carefully configured ...
Read MoreChanging the npm start-script of Node.js
The start-script of a Node.js application consists of all the commands that will be used to perform the specific tasks. When starting or initializing a Node.js project, there are a lot of predefined scripts that will be created for running the application. These scripts can be changed as per the need or demand of the project.Script commands are widely used for making different startup scripts of programs in both Node and React. 'npm start' is used for executing a startup script without typing its execution command.Package.json FileThis is the start-up script that needs to be added in the package.json file. ...
Read MoreFinding score of brackets in JavaScript
ProblemWe are required to write a JavaScript function that takes in a balanced square bracket string, str, as the first and the only argument.Our function should compute and return the score of the string based on the following rule −[] has score 1AB has a score A + B, where A and B are balanced bracket strings.[A] has score 2 * A, where A is a balanced bracket string.For example, if the input to the function isInputconst str = '[][]';Outputconst output = 2;ExampleFollowing is the code −const findScore = (str = '') => { const arr = [] ...
Read MoreFinding middlemost node of a linked list in JavaScript
Problem We are required to write a JavaScript function that takes in the head of a linked list as the first and the only argument. Our function should return the value stored in the middlemost node of the list. And if there are two middlemost nodes, we should return the second one of them. For example, if the list is like this: Input [4, 6, 8, 9, 1] Output const output = 8; Following is the code: Example class Node { constructor(data) { this.data = data; this.next = null; }; }; class LinkedList { constructor() { this.head = null; this.size = 0; }; }; LinkedList.prototype.add = function(data) { const newNode = new Node(data); let curr; if(this.head === null) { this.head = newNode; } else { curr = this.head; while(curr.next) { curr = curr.next; } ...
Read MoreBalancing two arrays in JavaScript
ProblemWe are required to write a JavaScript function that takes in two arrays of numbers, arr1 and arr2, as the first and the second argument.The sum of elements in arr1 and arr2 are different. Our function should pick one element from the first array and push it in the second array and pick one element from the second array and push it in the first array such that the sum of the elements of both the arrays become equal. We should return an array of these two elements.For example, if the input to the function isInputconst arr1 = [1, 2, ...
Read MorePlacing integers at correct index in JavaScript
ProblemWe are required to write a JavaScript function that takes in a string, str, which consists of only ‘[‘ or ‘]’. Our function is supposed to add the minimum number of square brackets ( '[' or ']', and in any positions ) so that the resulting bracket combination string is valid. And lastly, we should return the smallest number of brackets added.For example, if the input to the function isInputconst str = '[]]';Outputconst output = 1;Output ExplanationBecause, if we add ‘[‘ to the starting, the string will be balanced.Exampleconst findAdditions = (str = '') => { let left = 0 ...
Read MoreComputing Ackerman number for inputs in JavaScript
Ackermann FunctionThe Ackermann Function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree.ProblemWe are required to write a JavaScript function that takes in two numbers, m and n as the first and the second argument. Our function should return the Ackermann number A(m, n) defined byA(m, n) = n+1 if m=0 A(m, n) = A(m-1, 1) if m>0 , n=0 A(m, n) = A(m-1, A(m, n-1)) if m, n > 0Exampleconst m = 12; const n = ...
Read MoreASCII to hex and hex to ASCII converter class in JavaScript
ProblemWe are required to write a JavaScript class that have to member functions −toHex: It takes in a ASCII string and returns its hexadecimal equivalent.toASCII: It takes in a hexadecimal string and returns its ASCII equivalent.For example, if the input to the function is −Inputconst str = 'this is a string';Then the respective hex and ascii should be −74686973206973206120737472696e67 this is a stringExampleconst str = 'this is a string'; class Converter{ toASCII = (hex = '') => { const res = []; for(let i = 0; i < hex.length; i += 2){ ...
Read MoreLongest subarray with unit difference in JavaScript
ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argumentOur function should find and return the length of such a subarray where the difference between its maximum value and its minimum value is exactly 1.For example, if the input to the function is −const arr = [2, 4, 3, 3, 6, 3, 4, 8];Then the output should be −const output = 5;Output ExplanationBecause the desired subarray is [4, 3, 3, 3, 4]ExampleFollowing is the code −const arr = [2, 4, 3, 3, 6, 3, 4, 8]; const ...
Read More