1.0.9 โ€ข Published 2 years ago

@sensethenlove/loop-backwards v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years 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

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago