-
Notifications
You must be signed in to change notification settings - Fork 0
/
7kyu-maximum-product.js
43 lines (28 loc) · 1.18 KB
/
7kyu-maximum-product.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
// Task
// Given an array of integers , Find the maximum product obtained from multiplying 2 adjacent numbers in the array.
// Notes
// Array/list size is at least 2.
// Array/list numbers could be a mixture of positives, negatives also zeroes .
// Input >> Output Examples
// adjacentElementsProduct([1, 2, 3]); ==> return 6
// Explanation:
// The maximum product obtained from multiplying 2 * 3 = 6, and they're adjacent numbers in the array.
// adjacentElementsProduct([9, 5, 10, 2, 24, -1, -48]) ==> return 50
// Explanation:
// Max product obtained from multiplying 5 * 10 = 50.
// adjacentElementsProduct([-23, 4, -5, 99, -27, 329, -2, 7, -921]) ==> return -14
// Explanation:
// The maximum product obtained from multiplying -2 * 7 = -14, and they're adjacent numbers in the array.
// Playing with Numbers Series
// Playing With Lists/Arrays Series
// For More Enjoyable Katas
// ALL translations are welcomed
// Enjoy Learning !!
// Zizou
function adjacentElementsProduct(array) {
const result = [];
for (let i = 0; i < array.length - 1; i += 1) {
result.push(array[i] * array[i + 1]);
}
return Math.max(...result);
}