-
-
Notifications
You must be signed in to change notification settings - Fork 91
/
lunaditu_pyramid.js
47 lines (39 loc) · 915 Bytes
/
lunaditu_pyramid.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
/*
MODULE DONE BY https://github.com/Lunaditu
This module checks if the given array has a pyramid pattern and returns true if so.
*/
/**
* @param {Array} array
* @param {String} seperator (default is space (' '))
* @returns Boolean -> isPyramid
*/
function Streak (array, seperator=' ') {
if (array.length%2 == 0) return;
let first = array[0];
let mid = (array.length+1)/2;
let cont = true;
array.forEach((item, index) => {
if (cont) {
if (item.split(seperator).every((val, i, arr) => val == first)) { cont=true; }
else { cont = false; }
}});
return cont;
}
module.exports = {Streak}
/* TESTS */
let arr1 = [
'KEKW',
'KEKW KEKW',
'KEKW KEKW KEKW',
'KEKW KEKW',
'KEKW'
];
let arr2 = [
'KEKW',
'KEKW KEKW',
'KEKW KEKW KEKW',
'KEKW KEKWW',
'KEKW'
];
console.log(Streak(arr1));
console.log(Streak(arr2));