Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cc201010
VueProject
Commits
73dbe4fa
Commit
73dbe4fa
authored
Nov 18, 2021
by
cc201010
Browse files
tower and reduce js code
parent
064c8f60
Changes
3
Show whitespace changes
Inline
Side-by-side
reduce/index.js
0 → 100644
View file @
73dbe4fa
reduce/reduce.js
0 → 100644
View file @
73dbe4fa
const
dataset
=
[
'
red
'
,
'
blue
'
,
'
black
'
,
'
red
'
,
'
red
'
,
'
black
'
,
'
black
'
,
'
red
'
,
'
black
'
,
'
red
'
,
'
red
'
,
'
red
'
,
'
red
'
,
'
black
'
,
'
red
'
,
'
blue
'
,
'
red
'
,
'
blue
'
,
'
red
'
,
'
red
'
,
'
blue
'
,
'
red
'
,
'
blue
'
,
'
red
'
,
'
red
'
,
'
red
'
,
'
blue
'
,
'
red
'
,
'
purple
'
,
'
red
'
,
'
red
'
,
];
const
reducer
=
(
acc
,
currentValue
)
=>
{
//console.log(acc,currentValue)
if
(
acc
[
currentValue
]){
acc
[
currentValue
]
++
}
else
{
acc
[
currentValue
]
=
1
}
return
acc
}
const
result
=
dataset
.
reduce
(
reducer
,{})
console
.
log
(
result
)
dataset
.
map
(
v
=>
console
.
log
(
v
))
\ No newline at end of file
tower/tower.js
0 → 100644
View file @
73dbe4fa
const
height
=
process
.
argv
[
2
]
||
10
;
console
.
log
(
'
Hello CLI
'
,
height
);
// console.log('*');
// console.log('***');
// console.log('*****');
// Helpful formula: x * 2 - 1
const
bottomlayer
=
height
*
2
-
1
;
for
(
let
layer
=
1
;
layer
<=
height
;
layer
++
)
{
const
stones
=
layer
*
2
-
1
;
const
air
=
(
bottomlayer
-
stones
)
/
2
;
console
.
log
(
''
.
repeat
(
air
)
+
'
#
'
.
repeat
(
stones
)
+
''
.
repeat
(
air
));
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment