Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

skava / chain-able-deps   js

Repository URL to install this package:

Version: 6.0.4 

/ src / fp / __tests__ / firstLast.ts

import { isFunction } from '../../is'
import findLast from '../../fp/last'
import findLastIndex from '../../fp/lastIndex'
import findFirst from '../../fp/first'

test('can find last & last index in array', () => {
  expect(isFunction(findLast)).toBe(true)
  expect(isFunction(findLastIndex)).toBe(true)

  const array = [0, 1, 2, 3]
  const index = findLastIndex(array)
  const last = findLast(array)

  expect(array[index]).toEqual(last)
  expect(index).toBe(3)
})

test('can find last & last index in object', () => {
  const obj = { 0: 0, 1: 1, 2: 2, 3: 3 }
  const index = findLastIndex(obj)
  const last = findLast(obj)

  expect(obj[index]).toEqual(last)
  expect(index).toBe('3')
})

test('can find first', () => {
  const array = [0, 1, 2, 3]
  const first = findFirst(array)
  expect(first).toEqual(0)
})