Browse Source

add `Weekly Salary` task

Ethosa 3 years ago
parent
commit
448470d721
2 changed files with 37 additions and 0 deletions
  1. 19 0
      Languages/js-rush/task9/main.js
  2. 18 0
      Languages/js-rush/task9/readme.md

+ 19 - 0
Languages/js-rush/task9/main.js

@@ -0,0 +1,19 @@
+function main() {
+    console.log(weeklySalary([8, 8, 8, 8, 8, 0, 0]))
+    console.log(weeklySalary([10, 10, 10, 0, 8, 0, 0]))
+    console.log(weeklySalary([0, 0, 0, 0, 0, 12, 0]))
+}
+
+function weeklySalary(arr) {
+    let result = 0
+    arr.forEach(function(elem, i) {
+        let overtime = elem - 8 > 0? elem - 8: 0
+        if (i < 5)
+            result += 10*(elem-overtime) + 15*overtime
+        else
+            result += 20*(elem-overtime) + 30*overtime
+    })
+    return result
+}
+
+main()

+ 18 - 0
Languages/js-rush/task9/readme.md

@@ -0,0 +1,18 @@
+# Weekly Salary
+
+## Write a function that takes a list of `hours` and returns the total weekly salary.
+
+- The input list `hours` is listed sequentially, ordered from Monday to Sunday.
+- A worker earns $10 an hour for the first 8 hours.
+- For every overtime hour, he earns $15.
+- On weekends, the employer pays double the usual rate, regardless how many hours were worked previously that week. For instance, 10 hours worked on a weekday would pay 80+30 = $110, but on a weekend it would pay 160+60 = $220.
+
+### Examples
+```js
+weeklySalary([8, 8, 8, 8, 8, 0, 0]) ➞ 400
+weeklySalary([10, 10, 10, 0, 8, 0, 0]) ➞ 410
+weeklySalary([0, 0, 0, 0, 0, 12, 0]) ➞ 280
+```
+
+### Notes
+- Every element in the array is greater than or equal to 0.