Skip to content

Instantly share code, notes, and snippets.

@viticci
Created February 23, 2017 02:14
Show Gist options
  • Select an option

  • Save viticci/b4afbfdd3e8e000d3af8d3c1cc42c17a to your computer and use it in GitHub Desktop.

Select an option

Save viticci/b4afbfdd3e8e000d3af8d3c1cc42c17a to your computer and use it in GitHub Desktop.

Revisions

  1. viticci created this gist Feb 23, 2017.
    23 changes: 23 additions & 0 deletions Copied Markdown Title List Merge.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    // A clipping object is a JavaScript object that contains the following properties. Properties values may be null.
    // title - String
    // text - String
    // url - String
    // saveDate - Date

    // Merge function receives an array of clipping objects and returns the merged string

    function merge(clippings) {
    var merged = clippings.reduce(function(string, clipping) {
    var stringToAppend
    if (clipping.text != null) {
    stringToAppend = clipping.text
    } else if (clipping.url != null) {
    stringToAppend = '* [' + clipping.title + ']' + '(' + clipping.url + ')'
    }
    if (string.length == 0) {
    return stringToAppend
    }
    return string + "\n" + stringToAppend
    }, "")
    return merged
    }