-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8kyu.js
59 lines (43 loc) · 1.51 KB
/
8kyu.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
// In this simple assignment you are given a number and have to make it negative. But maybe the number is already negative?
// Examples
// makeNegative(1); // return -1
// makeNegative(-5); // return -5
// makeNegative(0); // return 0
// makeNegative(0.12); // return -0.12
function makeNegative(num) {
return num < 0 ? num : -num
}
// Make a function that will return a greeting statement that uses an input; your program should return, "Hello, <name> how are you doing today?".
function greet(name){
return `Hello, ${name} how are you doing today?`
}
// Your task is to write a function which returns the time since midnight in milliseconds.
function past(h, m, s){
let milliseconds = (s*1000) + (m*60000) + (h*3600000)
return milliseconds
}
//We need a function that can transform a string into a number. What ways of achieving this do you know?
const stringToNumber = function(str){
return Number(str)
}
//Count how often sign changes in array.
function catchSignChange(arr) {
let change = 0
for (let i = 0; i<arr.length; i++) {
if (arr[i]<0 && arr[i+1]>=0) {
change++
} else if (arr[i]>=0 && arr[i+1]<0 ) {
change++
}
}
return change
}
// Build a function that returns an array of integers from n to 1 where n>0.
// Example : n=5 --> [5,4,3,2,1]
const reverseSeq = n => {
let result = []
for (let i=n; i>0; i--){
result.push(i)
}
return result;
};