-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodewars8kyuNext.js
77 lines (59 loc) · 1.96 KB
/
codewars8kyuNext.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*The code provided is supposed replace all the dots . in the specified String str with dashes - */
var replaceDots = function(str) {
let arr = str.split('.');
let result = arr.join('-');
return result;
}
/* For example: month 2 (February), is part of the first quarter; month 6 (June), is part of the second quarter;
and month 11 (November), is part of the fourth quarter. */
const quarterOf = (month) => {
if (month === 1 || month === 2 || month === 3) return 1;
else if (month === 4 || month === 5 || month === 6) return 2;
else if (month === 7 || month === 8 || month === 9) return 3;
else return 4;
}
/* Given a set of numbers, return the additive inverse of each. Each positive becomes negatives, and the negatives become positives. */
function invert(array) {
for(let i = 0; i < array.length; i += 1) {
array[i] = -(array[i]);
}
return array;
}
// Complete the function that receives as input a string, and produces outputs according to the following table
function getDrinkByProfession(param){
let input = param.toLowerCase();
switch(input) {
case 'jabroni':
return 'Patron Tequila';
break;
case 'school counselor':
return 'Anything with Alcohol';
break;
case 'programmer':
return 'Hipster Craft Beer';
break;
case 'bike gang member':
return 'Moonshine';
break;
case 'politician':
return 'Your tax dollars';
break;
case 'rapper':
return 'Cristal';
break;
default:
return 'Beer';
break;
}
}
//In this simple assignment you are given a number and have to make it negative. But maybe the number is already negative?
function makeNegative(num) {
return (num > 0) ? -num : num;
}
// Given a non-empty array of integers, return the result of multiplying the values together in order.
function grow(x){
let result = x[0];
for(let i = 1; i < x.length; i += 1) {
result *= x[i];
} return result;
}