Commit 73dbe4fa authored by cc201010's avatar cc201010
Browse files

tower and reduce js code

parent 064c8f60
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
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));
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment