Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1
- let n = +gets();
- const factorial = (n) => {
- if (n<2) return 1
- return n * factorial(n-1);
- }
- print(factorial(n))
- 2
- const numberOfBunnies = +gets();
- const numberOfEars = (bunnies) => {
- if (bunnies === 0) return 0
- return 2 + numberOfEars(bunnies-1)
- }
- print(numberOfEars(numberOfBunnies))
- 4
- const numberOfBunnies = +gets();
- const numberOfEars = (bunnies) => {
- if (bunnies === 0)return 0;
- return bunnies%2===0 ? 3 + numberOfEars(bunnies-1): 2 + numberOfEars(bunnies-1);
- }
- print(numberOfEars(numberOfBunnies))
- 5
- const n = +gets();
- const pyramide = (n)=>{
- if(n === 0) return 0;
- return n+ pyramide(n-1);
- }
- print(pyramide(n))
- 6
- const num = +gets();
- const sum = (n) => {
- if(n === 0) return 0;
- return n%10 + sum(Math.trunc(n/10))
- }
- print(sum(num))
- 7
- let num = +gets();
- let count = 0;
- function sum(n) {
- if (n === 0) return 0;
- let first = (n % 10);
- if (first === 7) count++;
- sum(Math.trunc(n / 10));
- return count;
- };
- print(sum(num));
- 8
- let num = +gets();
- let count = 0;
- function sum(n) {
- if (n === 0) return 0;
- let first = (n % 10);
- let second = (Math.trunc(n / 10)) % 10;
- if (first === 8 ) {
- if(first === second){
- count+=2;
- }else {
- count++
- }
- }
- sum(Math.trunc(n / 10))
- return count;
- };
- print(sum(num));
- 9
- let num = +gets();
- let pows = +gets();
- const pow = (n, p) => {
- if(p === 0) return 1;
- return n* pow(n, p-1);
- }
- print(pow(num, pows))
- 10
- let string = gets();
- let count = 0;
- const findX = (string) => {
- if(!string.length) return;
- if(string[0] === 'x') count++;
- const newString = string.slice(1);
- findX(newString)
- return count
- }
- print(findX(string))
- 11
- let string = gets();
- let count = 0;
- const search = (string) => {
- if(!string.length) return;
- if (string[0] === 'h' && string[1] === 'i') count++
- const newString = string.slice(1);
- search(newString)
- return count
- }
- print(search(string))
- 12
- let string = gets();
- let final = ''
- let newString = '';
- const search = (string) => {
- if(!string.length) return;
- if(string[0] === 'p' && string[1] === 'i') {
- final += '3.14'
- newString = string.slice(2);
- } else {
- final += string[0];
- newString = string.slice(1)
- }
- search(newString)
- return final
- }
- print(search(string))
- 13
- const arrays = gets().split(',').map(Number);
- const index = +gets();
- const searchForSix = (arrays, index) => {
- if ( arrays[index] === 6) return true
- if ( index === arrays.length) return false;
- return searchForSix(arrays,index+1)
- }
- print(searchForSix(arrays, index))
- 14
- const arrays = gets().split(',').map(Number);
- const index = +gets();
- let count = 0;
- const searchForSix = (arrays, index) => {
- if ( index === arrays.length) return;
- if ( arrays[index] === 11) count++
- searchForSix(arrays,index+1)
- return count
- }
- 15
- const arrays = gets().split(',').map(Number);
- const index = +gets();
- const something = ( array , index) => {
- if ( index === array.length) return false;
- if (array[index]*10 === array[index+1]) return true;
- return something(array, index+1)
- }
- print(something(arrays, index))
Advertisement
Add Comment
Please, Sign In to add comment