This repository was archived by the owner on Feb 20, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ import timeSince from './timeSince'
8888import toPower from './to-power'
8989import truncate from './truncate'
9090import validateEmail from './validateEmail'
91+ import removeElementByIndex from './removeElementByIndex'
9192
9293export {
9394 reverseArrayInPlace ,
@@ -180,4 +181,5 @@ export {
180181 numberToString ,
181182 largest ,
182183 hex2hsl ,
184+ removeElementByIndex ,
183185}
Original file line number Diff line number Diff line change 1+ export default removeElementByIndex
2+
3+ /**
4+ * Original source: https://stackoverflow.com/a/5767335/10309455
5+ * This method removes the element from an array by index and returns edited array
6+ * @param {Array } array - base array
7+ * @param {Number } index - index to delete
8+ * @returns {Array } - array without deleted item
9+ */
10+
11+ function removeElementByIndex ( array , index ) {
12+ const updatedArray = [ ...array ]
13+ updatedArray . splice ( index , 1 )
14+ return updatedArray
15+ }
Original file line number Diff line number Diff line change 1+ import test from 'ava'
2+ import { removeElementByIndex } from '../src'
3+
4+ test ( 'Removes index from an array' , t => {
5+ const array = [ 1 , 2 , 3 ]
6+ const expected = [ 1 , 3 ]
7+ const actual = removeElementByIndex ( array , 1 )
8+
9+ t . deepEqual ( actual , expected )
10+ } )
You can’t perform that action at this time.
0 commit comments