-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathArray - squareUp b!.js
More file actions
43 lines (32 loc) · 830 Bytes
/
Copy pathArray - squareUp b!.js
File metadata and controls
43 lines (32 loc) · 830 Bytes
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
/*
Description:
This is a question from codingbat
Given an integer n greater than or equal to 0, create and return an array with the following pattern:
squareUp(3) => [0, 0, 1, 0, 2, 1, 3, 2, 1]
squareUp(2) => [0, 1, 2, 1]
squareUp(4) => [0, 0, 0, 1, 0, 0, 2, 1, 0, 3, 2, 1, 4, 3, 2, 1]
n<=1000.
Check out my other kata!
Matrix Diagonal Sort OMG
String -> N iterations -> String
String -> X iterations -> String
ANTISTRING
Array - squareUp b!
Matrix - squareUp b!
Infinitely Nested Radical Expressions
pipi Numbers!
PUZZLES
*/
function squareUp(n)
{
const arr0=Array(n).fill(0)
const arr=[];
const answ=[];
for (let i=n;i>0;i--){
arr.push(i)
}
for (let i=n;i>=0;i--){
answ.push(arr0.slice(0,i).concat(arr.slice(i)))
}
return [].concat(...answ.filter(v=>!v.every(v=>v===0)))
}