Skip to content

Instantly share code, notes, and snippets.

@KimiEatsCode
Last active August 26, 2015 03:49
Show Gist options
  • Save KimiEatsCode/86dca882e798d5003c74 to your computer and use it in GitHub Desktop.
Save KimiEatsCode/86dca882e798d5003c74 to your computer and use it in GitHub Desktop.
Create Object from a JS Function
A [Pen](http://codepen.io/sarahkmcaleer/pen/LVwaPG) by [Sarah McAleer](http://codepen.io/sarahkmcaleer) on [CodePen](http://codepen.io/).
[License](http://codepen.io/sarahkmcaleer/pen/LVwaPG/license).
function superCounter (x) {
var person = {
words: x.split(" ").length,
chars: x.split("").length,
avgLength: (x.split("").length/x.split(" ").length).toFixed(2),
spaces: x.split(/\s/g).length-1
}
var jsonText = JSON.stringify(person);
document.write(jsonText);
};
superCounter("A constructor is any function which is used As a constructor");
body {
color:#000;
text-align:center;
font-size:1.5em;
font-family: Chonburi;
margin-top:50px;
color:#7A2A3C;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment