Recursively Flatten an Object in JavaScript

AmitDiwan
Updated on 26-Aug-2020 09:38:41

389 Views

We are required to write a function that does the following transformation −If the input object is −const input = {    a: 0,    b: {x: {y: 1, z: 2}},    c: 3 };Then the output of the function should be −const output = {    a: 0,    'b.x.y': 1,    'b.x.z': 2,    c: 3 }We basically have to write a function that flattens a nested object. Will do this via recursion and the code for doing this will be −Exampleconst obj = {    a: 1,    b: {x: {y: 1, z: 2}},    c: 3 ... Read More

Parse Array to Equal Intervals in JavaScript

AmitDiwan
Updated on 26-Aug-2020 09:36:25

207 Views

Let’s say, we are required to write a function, say parseEqualInterval() that takes in an array of Numbers of strictly two elements as the first argument and a number n as the second argument and it inserts n-1 equidistant entries between the actual two elements of the original array so that it gets divided into n equal intervals.For example −// if the input array is const arr = [12, 48]; // and the interval is 4 //then the output array should be: const output = [12, 21, 30, 39, 48];This way the array got divided into 4 equal intervals. So, ... Read More

Check If Every Property on Object is the Same Recursively in JavaScript

AmitDiwan
Updated on 26-Aug-2020 09:34:21

425 Views

Let’s say, we are required to write a function, say isSame() that accepts a nested object and returns a boolean depending on the fact whether or not all the keys have the same values. When saying all the keys we mean all the last keys like if a key has a nested object as its value, we are required to traverse to the end of the nested object and check for that value.For example − If the object is −const obj = {    a: 1,    b: 1,    c: {       aa: 1    } };Then ... Read More

Rearrange Array in Maximum Minimum Form by JavaScript

AmitDiwan
Updated on 26-Aug-2020 09:31:44

267 Views

We are required to write a function, say minMax() that takes in an array of Numbers and rearranges the elements such that the greatest element appears first followed by the smallest elements then the second greatest element followed by second smallest element and so on.For example −// if the input array is: const input = [1, 2, 3, 4, 5, 6, 7] // then the output should be: const output = [7, 1, 6, 2, 5, 3, 4]So, let’s write the complete code for this function −Exampleconst input = [1, 2, 3, 4, 5, 6, 7]; const minMax = arr ... Read More

Count Elements in an Array Below or Above a Given Number in JavaScript

AmitDiwan
Updated on 26-Aug-2020 09:30:08

207 Views

Consider we have an array of Numbers that looks like this −const array = [3.1, 1, 2.2, 5.1, 6, 7.3, 2.1, 9];We are required to write a function that counts how many of the elements are in the array below / above a given number.For example, if the number is 5.25, the answer should be the following 5 elements, (3.1, 1, 2.2, 5.1, 2.1)and 3 elements above it −(6, 7.3, 9)Note − If any element is equal to the provided number, it should be counted as above the number.So, let’s write the code for this function −Exampleconst array = [3.1, ... Read More

Use PowerShell Help Commands

Chirag Nagrekar
Updated on 26-Aug-2020 08:27:28

5K+ Views

To get help for the particular command, you can use Get-Help (alias: help)  cmdlet with the command that you need help.For example, help Get-ServiceOnce you run this command, you will get the description of NAME, SYNOPSIS, SYNTAX, DESCRIPTION, RELATED LINKS, and REMARKS.Multiple parameters that support help as shown below-Full − Detailed help with parameter explanation and examples.help Get-Service -Full-Detailed − Detailed help of parameters and doesn’t include the examples.help Get-Service -Detailed-Examples − Only help related to examples will be displayed on the PowerShell screen.help Get-Service -Examples -Online − Help contents for the cmdlet will be searched online on the Microsoft ... Read More

Remove Windows Features Using PowerShell

Chirag Nagrekar
Updated on 26-Aug-2020 08:25:27

3K+ Views

To remove windows features, we can use command Remove-WindowsFeature command is used along with feature name.Remove-WindowsFeature Search-Service -VerboseVERBOSE: Uninstallation started... VERBOSE: Continue with removal? VERBOSE: Prerequisite processing started... VERBOSE: Prerequisite processing succeeded. Success Restart Needed Exit Code Feature Result ------- -------------- --------- -------------- True No Success {Windows Search Service} VERBOSE: Uninstallation succeeded.If the windows feature has the management tools like as in Web-Server (IIS) feature, you can add the same in the command line. If the server requires restart then you can add the -Restart parameter. For example, Remove-WindowsFeature Web-Server -IncludeManagementTools -Restart -VerboseIf we check the -Name parameter, it supports ... Read More

Install Windows Features with PowerShell

Chirag Nagrekar
Updated on 26-Aug-2020 08:23:44

6K+ Views

To install windows features on the server, Install-WindowsFeature cmdlet is used .Install-WindowsFeature Windows-Server-Backup -LogPath C:\Temp\Installfeatures.txt -VerboseIn the above example, Windows-Server-Backup feature will be installed on the local server and logs will be stored at location C:\Temp and file name InstallFeatures.txt.PS C:\Users\Administrator> Install-WindowsFeature Windows-Server-Backup -LogPath C:\Temp\Installfeatures.txt -Verbose VERBOSE: Installation started... VERBOSE: Continue with installation? VERBOSE: Prerequisite processing started... VERBOSE: Prerequisite processing succeeded. Success Restart Needed Exit Code Feature Result ------- -------------- --------- -------------- True No Success {Windows Server Backup} VERBOSE: Installation succeeded.You can also install the feature with the pipeline command, Get-WindowsFeature Windows-server-backup | Install-WindowsFeature -LogPath C:\Temp\Installfeatures.txt -VerboseIf your windows feature ... Read More

Get Windows Features Using PowerShell

Chirag Nagrekar
Updated on 26-Aug-2020 08:19:14

11K+ Views

To get the windows features and roles available or installed using PowerShell, you need to use the Get-WIndowsFeature cmdlet. That is obvious that Windows features and roles are available only on the server operating systems not on the client operating system.When you run the Get-WindowsFeature on the server operating system from Windows server 2008 onwards using PowerShell, you will get the output as below.The crossed symbol in the square box indicates that the feature is installed. You can also check the same using ‘Install State’. To get only Installed features on the server, you need to filter out the Install ... Read More

Find Number of Lists in a Tuple using Python

Pradeep Elance
Updated on 26-Aug-2020 08:11:56

346 Views

A python tuple is ordered and unchangeable. But it can also be made up of lists as its elements. Given a tuple made up of lists, let’s find out how many lists are present in the tuple.with len()In this approach we will apply the len function. The len() function will give the count of lists which are the elements of the tuple.Example Live DemotupA = (['a', 'b', 'x'], [21, 19]) tupB = (['n', 'm'], ['z', 'y', 'x'], [3, 7, 89]) print("The number of lists in tupA :" , len(tupA)) print("The number of lists in tupB :" , len(tupB))OutputRunning the above ... Read More

Advertisements