// Linear equation is calculated as follows: ax + by + c = 0. Write a function which calculates value of a linear equation, solveLinEquation.
// Linear equation is calculated as follows: ax + by + c = 0. Write a function which calculates value of a linear equation, solveLinEquation.
constsolveLinEquation=()=>{
return(-c-by)/a;
}
// Quadratic equation is calculated as follows: ax2 + bx + c = 0. Write a function which calculates value or values of a quadratic equation, solveQuadEquation.
// Declare a function name printArray.It takes array as a parameter and it prints out each value of the array.
// Write a function name showDateTime which shows time in this format: 08 / 01 / 2020 04: 08 using the Date object.
// Declare a function name printArray. It takes array as a parameter and it prints out each value of the array.
constprintArray=(arr)=>{
for(letiofarr){
console.log(i+"\n");
}
}
// Write a function name showDateTime which shows time in this format: 08/01/2020 04:08 using the Date object.
constshowDateTime=()=>{
constdates=newDate();
}
// showDateTime()
// 08 / 01 / 2020 04: 08
// Declare a function name swapValues.This function swaps value of x to y.
// 08/01/2020 04:08
// Declare a function name swapValues. This function swaps value of x to y.
constswapValues=(x,y)=>{
x=x+y;
y=x-y;
x=x-y;
return(x,y);
}
// swapValues(3, 4) // x => 4, y=>3
// swapValues(4, 5) // x = 5, y = 4
// Declare a function name reverseArray.It takes array as a parameter and it returns the reverse of the array(don't use method).
// console.log(reverseArray([1, 2, 3, 4, 5]))
// //[5, 4, 3, 2, 1]
// console.log(reverseArray(['A', 'B', 'C']))
// //['C', 'B', 'A']
// Declare a function name reverseArray. It takes array as a parameter and it returns the reverse of the array (don't use method).
constreverseArray=(arr)=>{
output=Array();
for(letiofarr){
output.unshift(i);
}
returnoutput;
}
// Declare a function name capitalizeArray.It takes array as a parameter and it returns the - capitalizedarray.
constcapitalizedArray=(arr)=>{
letoutput=[];
for(letiofarr){
output.push(i.toUpperCase());
}
returnoutput;
}
// Declare a function name addItem.It takes an item parameter and it returns an array after adding the item
functionaddItem(...item){
letoutput=[];
for(letiofitem){
output.push(i);
}
returnoutput;
}
// Declare a function name removeItem.It takes an index parameter and it returns an array after removing an item
functionremoveItem(arr,index){
arr.removeItem(arr.charAt(index));
}
// Declare a function name sumOfNumbers.It takes a number parameter and it adds all the numbers in that range.
functionsumOfNumbers(num){
letsum=0;
for(leti=1;i<=num;i++){
sum+=i;
}
returnsum;
}
// Declare a function name sumOfOdds.It takes a number parameter and it adds all the odd numbers in that - range.
functionsumOfOdds(num){
letsum=0;
for(leti=1;i<=num;i++){
if(i%2!=0){
sum+=i;
}
}
returnsum;
}
// Declare a function name sumOfEven.It takes a number parameter and it adds all the even numbers in that - range.
functionsumOfEven(num){
letsum=0;
for(leti=1;i<=num;i++){
if(i%2===0){
sum+=i;
}
}
returnsum;
}
// Declare a function name evensAndOdds.It takes a positive integer as parameter and it counts number of evens and odds in the number.
// evensAndOdds(100);
// The number of odds are 50.
// The number of evens are 51.
functionevensAndOdds(num){
letnumOdd=0;
letnumEven=0;
letsumEven=0;
letsumOdd=0;
for(leti=1;i<=num;i++){
if(i%2===0){
sumEven+=i;
numEven+=1;
}
else{
sumOdd+=i;
numOdd+=1;
}
}
letstatmentOdd=`The number of Odds are ${numOdd}`;
letstatementEven=`The number of Evens are ${numEven}`;
}
// Write a function which takes any number of arguments and return the sum of the arguments
// sum(1, 2, 3) // -> 6
// sum(1, 2, 3, 4) // -> 10
functionsumOfArgs(...nums){
letsum=0;
for(letiofnums){
sum+=i;
}
returnsum;
}
// Write a function which generates a randomUserIp.
functiongenRandnum(){
returnMath.floor(Math.random()*11);
}
functionRandomUserIp(){
letipArr=[];
for(leti=0;i<4;i++){
ipArr.push(Math.floor(Math.random()*256))
}
letip=ipArr.join(".");
returnip;
// Writ a function which generates a randomUserIp.
}
// Write a function which generates a randomMacAddress
// Declare a function name randomHexaNumberGenerator.When this function is called it generates a random hexadecimal number.The function return the hexadecimal number.