Skip to content

Instantly share code, notes, and snippets.

@guumaster
Created November 2, 2015 16:27
Show Gist options
  • Save guumaster/f635b7fc4fe1ce289d7f to your computer and use it in GitHub Desktop.
Save guumaster/f635b7fc4fe1ce289d7f to your computer and use it in GitHub Desktop.

Exercise 1

create modules to implement this features

  • convert string to title capitalized
  • sanitize a string
  • count word frequency
@diegoromera
Copy link

'use strict';


var stringIn = process.argv[2] || " escribe ";

var stringInArray = stringIn.split(" ");

stringInArray.forEach(function ( item, index, array ){
    var capital = firstLetter(item);
    var rest = restOfString(item);
    console.log(capital+rest);  
});


function firstLetter (stringIn) {
    return stringIn[0].charAt(0).toUpperCase();
}

function restOfString (stringIn){
    return stringIn.slice(1,stringIn.length);
}

module.exports = capitalLetter

@IGZdiegoherrera
Copy link

function capitalize(str) {

    let aux;
    let arr = [];

    str.split(/ +/).map(function(word) {
        aux = word.substring(0, 1).toUpperCase() + word.substring(1, word.length).toLowerCase();
        arr.push(aux);
    });

    return arr.join(" ");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment