Last active
November 11, 2020 05:16
-
-
Save petrusnog/72caff788bdc0b5189e517a094d2265e to your computer and use it in GitHub Desktop.
How to automate this code snippet?
This file contains hidden or 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
| var $i = 1; | |
| idea.keywords.forEach(function ( keyword ) { | |
| if ( $i < idea.keywords.length ) { | |
| this.keywords += keyword.text + ", "; | |
| } else { | |
| this.keywords += keyword.text + "."; | |
| } | |
| $i++; | |
| }); | |
| //Repetindo o trecho de código, pois não achei uma forma de automatizá-lo. | |
| var $i = 1; | |
| idea.concepts.forEach(function ( concept ) { | |
| if ( $i < idea.concepts.length ) { | |
| this.concepts += concept.text + ", "; | |
| } else { | |
| this.concepts += concept.text + "."; | |
| } | |
| $i++; | |
| }); |
This file contains hidden or 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
| //YEAAAAH! I FOUND IT! | |
| function showMetaFields ( meta_fields ) { | |
| var $i = 1; | |
| var content = ""; | |
| meta_fields.forEach(function ( meta_field ) { | |
| if ( $i < meta_fields.length ) { | |
| content += meta_field.text + ", "; | |
| } else { | |
| content += meta_field.text + "."; | |
| } | |
| $i++; | |
| }); | |
| return content; | |
| } | |
| showMetaFields( idea.keywords ); | |
| showMetaFields( idea.concepts ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment