append

append

  • (end: string) => (base: string) => string
  1. Append one string to another

    const appendCD = append('cd')
    
    appendCD('ab') // is 'abcd'
    const appendCD = append('cd')
    
    appendCD('ab') // is 'abcd'
    
    const appendCD = append('cd')
    
    appendCD('ab') // is 'abcd'
    const appendCD = append('cd')
    
    appendCD('ab') // is 'abcd'
    
  2. Sometimes we want to append a string. Below, Chris has a to-do list for today. Let's append a check or a box to each item.

    const itemsDone = [
      'email professor',
      'wish mom a happy birthday',
      'geology homework',
    ]
    const itemsToDo = ['get cat food', 'apply for internship']
    
    const format = (items, marker) => {
      const markItem = append(' ' + marker)
      return items.map(markItem).join('\n')
    }
    const list = `
    Items done
    ----------
    ${format(itemsDone, '🗹')}
    
    Items to do
    -----------
    ${format(itemsToDo, '☐')}
    `
    
    console.log(list)
    // prints
    //
    // Items done
    // ----------
    // email professor 🗹
    // wish mom a happy birthday 🗹
    // geology homework 🗹
    //
    // Items to do
    // -----------
    // get cat food ☐
    // apply for internship ☐
    const itemsDone = [
      'email professor',
      'wish mom a happy birthday',
      'geology homework',
    ]
    const itemsToDo = ['get cat food', 'apply for internship']
    
    const format = (items: string[], marker: string) => {
      const markItem = append(' ' + marker)
      return items.map(markItem).join('\n')
    }
    const list = `
    Items done
    ----------
    ${format(itemsDone, '🗹')}
    
    Items to do
    -----------
    ${format(itemsToDo, '☐')}
    `
    
    console.log(list)
    // prints
    //
    // Items done
    // ----------
    // email professor 🗹
    // wish mom a happy birthday 🗹
    // geology homework 🗹
    //
    // Items to do
    // -----------
    // get cat food ☐
    // apply for internship ☐
    
    const itemsDone = [
      'email professor',
      'wish mom a happy birthday',
      'geology homework',
    ]
    const itemsToDo = [
      'get cat food',
      'apply for internship',
    ]
    
    const format = (items, marker) => {
      const markItem = append(' ' + marker)
      return items.map(markItem).join('\n')
    }
    const list = `
    Items done
    ----------
    ${format(itemsDone, '🗹')}
    
    Items to do
    -----------
    ${format(itemsToDo, '☐')}
    `
    
    console.log(list)
    // prints
    //
    // Items done
    // ----------
    // email professor 🗹
    // wish mom a happy birthday 🗹
    // geology homework 🗹
    //
    // Items to do
    // -----------
    // get cat food ☐
    // apply for internship ☐
    const itemsDone = [
      'email professor',
      'wish mom a happy birthday',
      'geology homework',
    ]
    const itemsToDo = [
      'get cat food',
      'apply for internship',
    ]
    
    const format = (
      items: string[],
      marker: string
    ) => {
      const markItem = append(' ' + marker)
      return items.map(markItem).join('\n')
    }
    const list = `
    Items done
    ----------
    ${format(itemsDone, '🗹')}
    
    Items to do
    -----------
    ${format(itemsToDo, '☐')}
    `
    
    console.log(list)
    // prints
    //
    // Items done
    // ----------
    // email professor 🗹
    // wish mom a happy birthday 🗹
    // geology homework 🗹
    //
    // Items to do
    // -----------
    // get cat food ☐
    // apply for internship ☐