Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.
Andrew Redican edited this page Dec 15, 2017 · 29 revisions

Read about all methods here

Examples

Dummy object used in examples:

const assessments= {
    nancy_mccarty : {
        A1: {
            userID: "nancy_mccarty",
            userName: "Nancy McCarty",
            id : "A1",
            score : 0.75,
            date_created : 151208443563,
            date_signed : 151208448055,
            date_approved: 151208471190,
            answers: ['Yes','No','No','Yes','No']
        },
        A2: {
            userID: "nancy_mccarty",
            userName: "Nancy McCarty",
            id : "A2",
            score : 0.9,
            date_created : 151208450090,
            date_signed : false,
            date_approved: false,
            answers: ['No','No','No','Yes','Yes']
        }
    },
    george_richardson : {
        A2: {
            userID: "george_richardson",
            userName: "George Richardson",
            id : "A2",
            score : 0.35,
            date_created : 1512076585058,
            date_signed : false,
            date_approved: false,
            answers: ['No','Yes','Yes','Yes','Yes']
        }
    },
    tom_hughe : { 
        A4: {
            userID: "tom_hughe",
            userName: "Tom Hughe",
            id : "A4",
            score : 0.75,
            date_created : 1512076575026,
            date_signed : 1512076609894,
            date_approved: false,
            answers: ['Yes','No','No','Yes','No']
        },
        M1: {
            userID: "tom_hughe",
            userName: "Tom Hughe",
            id : "M1",
            score : false,
            date_created : 1512076587361,
            date_signed : false,
            date_approved: false,
            answers: [false,false,false,false,false]
        }
    },
    heidy_white : {
        L2: {
            userID: "heidy_white",
            userName: "Heidy White",
            id : "L2",
            score : false,
            date_created : 15120765766312,
            date_signed : false,
            date_approved: false,
            answers: [false,false,false,false,false]
        }
    }
}

length( identity )

Returns the number of keys or properties contained in identity.

  let listA = ['Henry','Lissa','Michael','Tom'];

  let listB = {
     nancy_mccarty: "Nancy McCarty",
     george_richardson: "George Richardson",
     heidy_white: ["Heidy White","Anita_Salgado"]
  };


  length(listA) //result: 4


  length(listB) //result: 3


  length(68)

  length(null)

  length('hello world')

  length({})

  length('') // result: 0 

exists( collection, identity, [optional=depth] )

Performs deep search on collection for an identical match to identity. assessments

  exists(assessments,{userName: "Tom Hughe"})

  exists(assessments,{score : false})

  exists(assessments,{id : "M1"})
  //result: true


  const obj = { answers: [false,false,false,false,false] };

  exists(assessments,obj)
  //result: true

onlyExisting( collection, identities, [optional=depth] )

For each identity in identities, performs a deep search on collection using exists, to shorten the list identities to those that were found. assessments

  const userIDs = ['nancy_mccarty','sean_mccollin','george_richardson','giselle_lopez'];

  onlyExisting(assessments, userIDs)
  //result: ['nancy_mccarty','george_richardson']
     

onlyMissing( collection, identities, [optional=depth] )

For each identity in identities, performs a deep search on collection using exists, to shorten the list identities to those that were not found. assessments

  const userIDs = ['nancy_mccarty','sean_mccollin','george_richardson','giselle_lopez'];

  onlyExisting(assessments, userIDs)
  //result: ['sean_mccollin','giselle_lopez']
     

isFalsy( identity )

Checks if identity has or false or false-like values. These include: null, undefined, '', false, and 0.

  isFalsy(null)

  isFalsy(undefined)

  isFalsy(false)

  isFalsy(0)
  //result: true


  isFalsy([1,'domingo',null])

  isFalsy(-3)

  isFalsy({})

  //result: false
     

isTruthy( identity )

Checks if identity is non-falsy.


  isTruthy([1,'domingo',null])

  isTruthy(-3)

  isTruthy([])

  isTruthy({ propA: 'some text' })
  //result: true


  isTruthy(null)

  isTruthy(undefined)

  isTruthy(false)

  isTruthy(0)
  //result: false
     

foundTruthy( collection, identity, [optional=depth] )

Performs deep search on collection, and evaluate if isTruthy on the first identical match to identity.

  var testObj = {
         userID: "nancy_mccarty",
         userName: "Nancy McCarty",
         id : "A2",
         score : 0.9,
         date_created : 151208450090,
         date_signed : false,
         deeplynested : {
             propA: 88,
             propB: 0,
             newDepth : { propC: 'I have some answers' }
         }

  foundTruthy(testObj,{date_created : false})
  //result: true

  foundTruthy(testObj,'propA')
  //result: true

  foundTruthy(testObj,'deeplynested')
  //result : true

  foundTruthy(testObj,'propD')
  //result : false

foundFalsy( collection, identity, [optional=depth] )

Performs deep search on collection, and evaluate if isFalsy on the first identical match to identity.

  var testObj = {
         userID: "nancy_mccarty",
         userName: "Nancy McCarty",
         id : "A2",
         score : 0.9,
         date_created : 151208450090,
         date_signed : false,
         deeplynested : {
             propA: 88,
             propB: 0,
             propC: 'I have some answers'
         }

  foundFalsy(testObj,{ date_signed : false })
  //result: true

  foundFalsy(testObj,['foo','bar'])
  //result: undefined

  foundFalsy(testObj,{score: false})
  //result: false

  foundFalsy(testObj,'propB')
  //result: true

onlyTruthy( collection, identities, property, [optional=depth] )

Performs deep search on collection to find a match to the identity, will return the entity containing of the first instance matched. assessments

  const team = ['Nancy McCarty','George Richardson','Tom Hughe','heidy_white'];
  
  onlyTruthy( assessments, team, 'date_signed' )
  //result: ['Nancy McCarty','Tom Hughe']


  const team2 = {
     nancy_mccarty : "Nancy McCarty",
     george_richardson : "George Richardson",
     tom_hughe : "Tom Hughe",
     heidy_white : "Heidy White"
  };

  onlyTruthy( assessments, team2, 'date_signed' )
  //result: { nancy_mccarty : "Nancy McCarty", tom_hughe : "Tom Hughe" }
     

onlyFalsy( collection, identities, property, [optional=depth] )

For each identity in identities, performs a deep search on collection using exists, and evaluates if isFalsy on the first identical match of property to shorten the list identities to those that were found and also truthy. assessments

  const team = [
     'Nancy McCarty',
     'George Richardson',
     'Tom Hughe',
     'heidy_white',
     'Scott Wickham'
  ];
  
  onlyFalsy( assessments, team, 'date_signed' )
  //result: ['Nancy McCarty','George Richardson','Tom Hughe','heidy_white']


  const team2 = {
     nancy_mccarty : "Nancy McCarty",
     george_richardson : "George Richardson",
     tom_hughe : "Tom Hughe",
     heidy_white : "Heidy White",
     scott_wickham : "Scott Wickham"
  };

  onlyFalsy( assessments, team2, { date_signed : 65 } )
  //result: {
       'nancy_mccarty':'Nancy McCarty',
       'george_richardson':'George Richardson',
       'tom_hughe':'Tom Hughe',
       'heidy_white':'Heidy White'
   }