1.0.9 โ€ข Published 1 year ago

@sensethenlove/loop-backwards v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

๐Ÿ•‰ @sensethenlove/loop-backwards

๐Ÿ™ Description

Loop an array backwards! Give loopBackwards() an array and a callback. On each iteration calback provides the current item, a splice function, and the current index. If the splice function is called the item is removed from the array. If the splice function is called & the current item is a DOM element the item is removed from the array & the item is removed from the DOM

โ˜ฏ๏ธ Install

pnpm add @sensethenlove/loop-backwards

๐Ÿ’› Example: Array of numbers

import loopBackwards from '@sensethenlove/loop-backwards'

loopBackwards(numbers, (number, splice, index) => {
  if (number === 9 || index === 9) splice()
})

๐Ÿงก Example: Array of objects

loopBackwards(items, ({ foo }, splice) => {
  if (foo === 'bar') splice()
})

๐Ÿ’š Example: Array of DOM elements

const elements = document.querySelectorAll('div')

loopBackwards(Array.from(elements), (element, splice) => {
  if (element.getAttribute('foo') === 'bar') splice()
})

๐Ÿ’– Our helpful packages!

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago