Skip to content

udhayakumarcp/JS_Functions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JAVASCRIPT & TYPESCRIPT Questions and Answers

  1. Write a JavaScript program to get the current date.

Expected Output : mm-dd-yyyy, mm/dd/yyyy or dd-mm-yyyy, dd/mm/yyyy

  1. Write a JavaScript program to convert temperatures to and from Celsius, Fahrenheit. [ Formula : c/5 = (f-32)/9 [ where c = temperature in Celsius and f = temperature in Fahrenheit ]

Expected Output : 60°C is 140 °F 45°F is 7.222222222222222°C

  1. Your task is to split the chocolate bar of given dimension n x m into small squares. Each square is of size 1x1 and unbreakable. Implement a function that will return the minimum number of breaks needed.

For example if you are given a chocolate bar of size 2 x 1 you can split it into single squares in just one break, but for size 3 x 1 you must do two breaks.

If input data is invalid you should return 0 (as in no breaks are needed if we do not have any chocolate to split). Input will always be a non-negative integer.

  1. A digital root is the recursive sum of all the digits in a number. Given n, take the sum of the digits of n. If that value has more than one digit, continue reducing in this way until a single-digit number is produced. This is only applicable to the natural numbers.

Here's how it works: digital_root(16) => 1 + 6 => 7 digital_root(942) => 9 + 4 + 2 => 15 ... => 1 + 5 => 6 digital_root(132189) => 1 + 3 + 2 + 1 + 8 + 9 => 24 ... => 2 + 4 => 6 digital_root(493193) => 4 + 9 + 3 + 1 + 9 + 3 => 29 ... => 2 + 9 => 11 ... => 1 + 1 => 2

  1. Given a list lst and a number N, create a new list that contains each number of lst at most N times without reordering. For example if N = 2, and the input is [1,2,3,1,2,1,2,3], you take [1,2,3,1,2], drop the next [1,2] since this would lead to 1 and 2 being in the result 3 times, and then take 3, which leads to [1,2,3,1,2,3].

Example deleteNth ([1,1,1,1],2) // return [1,1] deleteNth ([20,37,20,21],1) // return [20,37,21]

  1. How Do You Implement Inheritance In Typescript?

  2. Write a JavaScript program that accept two integers and display the larger

  3. Write a JavaScript conditional statement to find the sign of a product of three numbers. Display an alert box with the specified sign.

Sample numbers : 3, -7, 2 Output : The sign is -

  1. .Write a JavaScript conditional statement to sort three numbers. Display an alert box to show the result.

Sample numbers : 0, -1, 4 Output : 4, 0, -1

  1. Write a JavaScript program to construct the following pattern, using a nested for loop.



About

Simple Javascript Functions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors