Last active
May 9, 2016 21:28
-
-
Save arecvlohe/8bcd661a5193c19c2e5bcc53324b2c2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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