Skip to content

Instantly share code, notes, and snippets.

@blessedjasonmwanza
Created May 3, 2022 14:23
Show Gist options
  • Save blessedjasonmwanza/2ad9150e3d360b98405c7f015d98636e to your computer and use it in GitHub Desktop.
Save blessedjasonmwanza/2ad9150e3d360b98405c7f015d98636e to your computer and use it in GitHub Desktop.
Capitalize first character of each word
// Adapted from : https://www.codewars.com/kata/5390bac347d09b7da40006f6/train/javascript
String.prototype.toJadenCase = function () {
let str = this.toString();
// split it to an array,
// capitalize each item
// join it with a space
str = str.split(' ');
return str.map(word => word.charAt(0).toUpperCase()+ word.slice(1)).join(' ');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment