Code Monkey home page Code Monkey logo

katas-navidad's Introduction

SOLUCIONES





Kata-01. Numbers to Letters

function switcher(x){
    const alphabet={1:'z',2:'y',3:'x',4:'w',5:'v',6:'u',7:'t',8:'s',9:'r',10:'q',
  11:'p',12:'o',13:'n',14:'m',15:'l',16:'k',17:'j',18:'i',19:'h',20:'g',
  21:'f',22:'e',23:'d',24:'c',25:'b',26:'a',27:'!',28:'?',29:' '}
    
  return x.map(function change(v) {
    return alphabet[v*1]}).join('');
  }


switcher(['24', '12', '23', '22', '4', '26', '9', '8']);



Kata-02. Remove First and Last Character

function removeChar(str){
    return str = str.slice(1,-1);
    };

removeChar('eloquent');



Kata-03. Vowel Count

function getCount(str) {
    let vowelsCount = 0;
    let stringToArray = str.split('');
    for (i = 0; i < stringToArray.length; i++) {
      if (stringToArray[i] === 'a' || stringToArray[i] === 'e' || stringToArray[i] === 'i' || stringToArray[i] === 'o' || stringToArray[i] === 'u') {
        vowelsCount = vowelsCount + 1;
      }
    }
    return vowelsCount;
}


getCount("abracadabra");



Kata-04. Sum Mixed Array

function sumMix(x){
    let integer = []; 
    for (i = 0; i < x.length; i++) {
     integer.push (parseInt (x[i], 10));
    }

    let sumTotal = 0;

    for (i = 0; i < integer.length; i++) {
        sumTotal = sumTotal + integer[i];
    }
    return sumTotal;
}

sumMix([9, 3, '7', '3']);

Kata-05. Count of positives / sum of negatives

function countPositivesSumNegatives(input) {
    let positiveNum = [];
    let negativeNum = [];
    if (input == null || input.length < 1) {
        return [];
    }
   for(i = 0; i < input.length; i++) {
        if(input[i] > 0 ) {
            positiveNum.push(input[i]);
        }
        else {
            negativeNum.push(input[i]);
        }
    }

    let countPositiveNum = positiveNum.length;
    let sumNegativeNum = negativeNum.reduce(function(a,b){
        return a + b },0);
    
    let result = [];
    result.push(countPositiveNum, sumNegativeNum);
    return result;
    }

Kata-06. Get the mean of an array

function getAverage(marks){
    let sum = 0;
    for (let i=0; i < marks.length; i++) {
        sum = sum + parseInt(marks[i], 10);
    }
    let average = Math.floor(sum/marks.length);
    return average;
}




getAverage([1,2,3,4,5,])
getAverage([1,1,1,1,1,1,1,2])

Kata-07. Find numbers which are divisible by given number

function divisibleBy(numbers, divisor){
    let numbersArray = [];
    for (let i=0; i < numbers.length; i++) {
        if (numbers[i] % divisor == 0) {
                numbersArray.push(numbers[i]);
        }
    }
    return numbersArray;
}



divisibleBy([1,2,3,4,5,6], 2);
divisibleBy([1,2,3,4,5,6], 3);

Kata-09. Credit Card Mask

function maskify(cc) {
    cc = cc.replace(/\d(?=\d{4})/g, "#");
    return cc;
}



maskify('4556364607935616');

Kata-10. Flatten

let flatten = function (array){
    return array.reduce((acc, val) => Array.isArray(val) ? acc.concat(flatten(val)) : acc.concat(val), []);
  }


flatten([[1, 2, 3], ["a", "b", "c"], [1, 2, 3]]);

*Tiene errores, no he conseguido que devuelva solo un nivel de array sino que devuelva todo en una sola array.

katas-navidad's People

Watchers

James Cloos avatar Carles avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.