Build a Map from Two Arrays of Values and Keys in JavaScript

AmitDiwan
Updated on 30-Sep-2020 13:24:32

6K+ Views

Suppose, we have two arrays −const keys = [0, 4, 2, 3, 1]; const values = ["first", "second", "third", "fourth", "fifth"];We are required to write a JavaScript function that takes in the keys and the values array and maps the values to the corresponding keys. The output should be −const map = {    0 => 'first',    4 => 'second',    2 => 'third',    3 => 'fourth',    1 => 'fifth' };ExampleFollowing is the code −const keys = [0, 4, 2, 3, 1]; const values = ["first", "second", "third", "fourth", "fifth"]; const buildMap = (keys, values) => { ... Read More

Remove Array Duplicates by Property in JavaScript

AmitDiwan
Updated on 30-Sep-2020 13:23:13

237 Views

Suppose, we have an array of objects like this −const arr = [{name: "Jack", age: "14"}, {name: "bob", age: "14"}, {name: "sue", age: "21"}, {name: "Jill", age: "16"}, {name: "Jack", age: "21"}];We are required to write a JavaScript function that takes in one such array and removes all the objects that have duplicate values for the name.Therefore, for the above array, the output should be −const arr = [{name: "Jack", age: "14"}, {name: "bob", age: "14"}, {name: "sue", age: "21"}, {name: "Jill", age: "16"}];ExampleFollowing is the code −const arr = [    {name: "Jack", age: "14"},    {name: "bob", age: ... Read More

Convert Array to Key-Value Pair in JavaScript

AmitDiwan
Updated on 30-Sep-2020 13:21:57

6K+ Views

Suppose we have an array like this −const arr = [ {"name": "Rahul", "score": 89},    {"name": "Vivek", "score": 88},    {"name": "Rakesh", "score": 75},    {"name": "Sourav", "score": 82},    {"name": "Gautam", "score": 91},    {"name": "Sunil", "score": 79}, ];We are required to write a JavaScript function that takes in one such array and constructs an object where name value is the key and the score value is their value.Use the Array.prototype.reduce() method to construct an object from the array.ExampleFollowing is the code −const arr = [    {"name": "Rahul", "score": 89},    {"name": "Vivek", "score": 88},    {"name": ... Read More

Pick Random Elements from an Array in JavaScript

AmitDiwan
Updated on 30-Sep-2020 13:20:15

2K+ Views

Suppose, we have an array of literals that contains no duplicate elements like this −const arr = [2, 5, 4, 45, 32, 46, 78, 87, 98, 56, 23, 12];We are required to write a JavaScript function that takes in an array of unique literals and a number n.The function should return an array of n elements all chosen randomly from the input array and no element should appear more than once in the output array.ExampleFollowing is the code −const arr = [2, 5, 4, 45, 32, 46, 78, 87, 98, 56, 23, 12]; const chooseRandom = (arr, num = 1) ... Read More

Changing Color Randomly in JavaScript

AmitDiwan
Updated on 30-Sep-2020 13:19:12

415 Views

We are required to write a JavaScript function, let’s say randomColor that returns a randomly generated hex color every time it is called.ExampleFollowing is the code −const randomColor = () => {    let color = '#';    for (let i = 0; i < 6; i++){       const random = Math.random();       const bit = (random * 16) | 0;       color += (bit).toString(16);    };    return color; }; console.log(randomColor()); console.log(randomColor()); console.log(randomColor()); console.log(randomColor()); console.log(randomColor()); console.log(randomColor()); console.log(randomColor());OutputThis will produce the following output in console −#762b46 #cfa0bf #a20ee1 #c2f7e0 #5d5822 #380f30 #805408

Operation Cycle Method in Estimation of Working Capital

Mandalika
Updated on 29-Sep-2020 14:00:27

3K+ Views

Operation cycle method considers total cycle of operations, from raw materials to finished goods, from accounts payable to net cash.The times taken to complete these operations are called operating cycle time.If the operating cycle is long then, requirement of working capital is less, if the operating cycle is less then, requirement of working capital is less.FormulasWorking capital = CGS(E)* D/365 + CBHere, CGS (E) = estimated cost of goods sold, D = days in operating cycle, CB = Cash/Bank balanceRM Stock = PU(E) * Cu * (Hp/365)Here, PU(E) = production units estimated, Cu = cost per unit, HP = holding ... Read More

Regression Analysis Method in Estimation of Working Capital

Mandalika
Updated on 29-Sep-2020 13:59:10

936 Views

In regression analysis method, statistical tool is used to calculate working capital.CalculationsWorking capital = Int + m*R            Int = intercept, m = slope, R = RevenueΣy = na + bΣxΣxy = aΣx + bΣ2            Where x = sales, y = working capital, n = yearsAdvantages of this method include −Accurate method for bigger volume of data.It is a proven method.Disadvantages of this method include −Not east to understand.Calculations are complicated as compared to percentage sales method.ExampleBy using following table, calculate the data using regression analysis method, forecasted sales = 500YearSales ... Read More

Percentage of Sales Method in Estimation of Working Capital

Mandalika
Updated on 29-Sep-2020 13:57:48

1K+ Views

Percentage of sales method is the traditional method to find out working capital. This method is based on historical relationship between sales and working capital. Each of historical value is converted to percentage of net sales and those values are used to forecast.Steps involved in this method are −Determine historical relationship between sales and working capital.Forecast sales for future date.Apply percentage sales of method to get forecasted value.FormulaPercentage of sales method = WCc*100/S Here WCc = components of working capital, S = yearly salesAdvantages of this method are −Easy to understand.Calculations are simple.Disadvantages of this method are −Relationship between sales ... Read More

Modern Methods of Appraisal in Accounting

Mandalika
Updated on 29-Sep-2020 13:56:52

391 Views

Appraisal methods are categorised into two types. Each method has its own merits and de-merits. One of the methods used by companies are modern methods which are divided into following typesMBOMBO means Management by Objectives. This concept was developed by Peter F.Drucker in 1954. It is the process where, both superior and subordinates identifies goal for each individual and define those by identifying their areas of responsibilities.This method follows goal setting, performance, comparison and reviews. Its main drawbacks are setting un measurable goals, time taking, no trust.Behaviour anchoredIt varies with performance dimensions. Benefits are combinations of narratives, critical and quantified. ... Read More

Traditional Methods of Appraisal in Accounting

Mandalika
Updated on 29-Sep-2020 13:55:12

467 Views

Appraisal methods are categorised into two types. Each method has its own merits and de-merits. One of the methods used by companies are traditional methods, which are divided into following types −Ranking method − It is the oldest method used in performance appraisal. In this method, employees are ranked according to their order of worth. It is difficult to rank individually if the employee number is large.Paired comparison − In this method, employees are compared according to one trait. Score of employee is based on their consideration on that particular trait. Better employee is ticked among others. The more the ... Read More

Advertisements