Skip to content

Instantly share code, notes, and snippets.

@arecvlohe
Last active May 9, 2016 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arecvlohe/8bcd661a5193c19c2e5bcc53324b2c2a to your computer and use it in GitHub Desktop.
Save arecvlohe/8bcd661a5193c19c2e5bcc53324b2c2a to your computer and use it in GitHub Desktop.
'use strict'
function stringCount(object) {
let count = 0
if (typeof object === 'object' && !Array.isArray(object) && object) {
Object.keys(object).forEach(key => {
if (typeof object[key] === 'string')
count++
if (Array.isArray(object[key]))
count+= stringCount(object[key])
})
}
if (Array.isArray(object) && object) {
object.forEach(item => {
if (typeof item === 'string')
count++
})
}
return count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment