-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcenturyFromYear.html
More file actions
105 lines (72 loc) · 2.79 KB
/
centuryFromYear.html
File metadata and controls
105 lines (72 loc) · 2.79 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Javascript</title>
</head>
<body>
<script>
function centuryFromYear(year) {
if (year%100 == 0) {
return year/100; //output = 17
}
else {
return (year - (year%100))/100 + 1;
}
}
function checkPalindrome(inputString) {
return inputString === inputString.split('').reverse().join('');
}
// Example
// For inputString = "aabaa", the output should be
// checkPalindrome(inputString) = true;
// For inputString = "abac", the output should be
// checkPalindrome(inputString) = false;
// For inputString = "a", the output should be
// checkPalindrome(inputString) = true.
function adjacentElementsProduct(inputArray) {
var maxProduct = inputArray[0] * inputArray[1];
for (var i = 0; i < inputArray.length; i++) {
if (maxProduct < inputArray[i] * inputArray[i+1]) {
maxProduct = inputArray[i] * inputArray[i+1];
}
}
return maxProduct;
}
// Example
// For inputArray = [3, 6, -2, -5, 7, 3], the output should be
// adjacentElementsProduct(inputArray) = 21.
// 7 and 3 produce the largest product.
// Input/Output
// [time limit] 4000ms (js)
// [input] array.integer inputArray
// An array of integers containing at least two elements.
// Guaranteed constraints:
// 2 ≤ inputArray.length ≤ 10,
// -1000 ≤ inputArray[i] ≤ 1000.
// [output] integer
// The largest product of adjacent elements.
function shapeArea(n) {
return (n * n) + ((n-1)*(n-1));
}
// Below we will define an n-interesting polygon. Your task is to find the area of a polygon for a given n.
// A 1-interesting polygon is just a square with a side of length 1. An n-interesting polygon is obtained by taking the n - 1-interesting polygon and appending 1-interesting polygons to its rim, side
// by side. You can see the 1-, 2-, 3- and 4-interesting polygons in the picture below.
function makeArrayConsecutive2(statues) {
var min = max = statues[0];
for(var i = 0; i < statues.length; i++) {
min = statues[i]<min ? statues[i] : min;
max = statues[i]>max ? statues[i] : max;
}
return max-min-statues.length+1;
}
// Ratiorg got statues of different sizes as a present from CodeMaster for his birthday, each statue having an non-negative integer size. Since he likes to make things perfect, he wants to arrange them from smallest to largest so that each statue will be bigger than the previous one exactly by 1. He may need some additional statues to be able to accomplish that. Help him figure out the minimum number of additional statues needed.
// Example
// For statues = [6, 2, 3, 8], the output should be
// makeArrayConsecutive2(statues) = 3.
// Ratiorg needs statues of sizes 4, 5 and 7.
</script>
</body>
</html>