towerCombination WIP
codewars 7 kyu
by trentHarlem
HTML
towerCombination(3) returns 6, because only the following possibilities can be achieved.<br>
<br>
| x 0 0 |<br>
| 0 x 0 |<br>
| 0 0 x |<br>
<br>
| x 0 0 |<br>
| 0 0 x |<br>
| 0 x 0 |<br>
<br>
| 0 x 0 |<br>
| x 0 0 |<br>
| 0 0 x |<br>
<br>
| 0 x 0 |<br>
| 0 0 x |<br>
| x 0 0 |<br>
<br>
| 0 0 x |<br>
| x 0 0 |<br>
| 0 x 0 |<br>
<br>
| 0 0 x |<br>
| 0 x 0 |<br>
| x 0 0 |<br>
towerCombination(4) returns ??, because only the following possibilities can be achieved.<br>
<br>
| x 0 0 0|<br>
| 0 x 0 0|<br>
| 0 0 x 0|<br>
| 0 0 0 x|<br>
<br>
| 0 x 0 0|<br>
| x 0 0 0|<br>
| 0 0 x 0|<br>
| 0 0 0 x|<br>
<br>
| 0 0 x 0|<br>
| 0 x 0 0|<br>
| x 0 0 0|<br>
| 0 0 0 x|<br>
<br>
| 0 0 0 x|<br>
| 0 0 x 0|<br>
| 0 x 0 0|<br>
| x 0 0 0|<br>
<br>
| x 0 0 0|<br>
| 0 0 0 x|<br>
| 0 0 x 0|<br>
| 0 x 0 0|<br>
<br>
| 0 x 0 0|<br>
| x 0 0 0|<br>
| 0 0 0 x|<br>
| 0 0 x 0|<br>
JavaScript
// Work in Progress
/* function towerCombination(n) {
let num = 1;
for(let i = 2; i <= n; i++)
num *= i;
return num;
}
*/
function towerCombination(n) {
let combos = n;
for (let i = n; i > 2; i--) {
combos = combos * (i - 1)
}
return combos
}
const removeDuplicateWords = s => [...new Set(s.split(' '))].join(' ')
console.log(removeDuplicateWords('trent trent'))
function spinWords(string){
return string.split(' ').map(word=>(word.length>4)?word.split('').reverse().join(''):word).join(' ')
}
console.log(spinWords('Hey fellow warriors'))
console.log(spinWords('this is a test'))
/* function towerCombination(num) {
let result = 0;
let count = num
while (count > 1) {
count--;
result += 1*num;
}
return result;
}
*/
/* [Arguments] { '0': 2 }
[Arguments] { '0': 1 }
[Arguments] { '0': 3 }
[Arguments] { '0': 2 }
[Arguments] { '0': 100 }
[Arguments] { '0': 99 } */
/*
function towerCombination(n){
return n*n-n
}
*/
console.log(towerCombination(2), '2')
console.log(towerCombination(3), '6')
console.log(towerCombination(4), '?')
/// PASSES ONLY 1st test
/* function towerCombination(n){
if(n===2) {
return n
} else {
return n+n
}
} */