@bemoje/arr-clone
v1.0.2
Published
Shallow clone of provided array, 'arr'.
Downloads
3
Maintainers
Readme
@bemoje/arr-clone
Shallow clone of provided array, 'arr'.
Version
Travis CI
Dependencies
Stats
Donate
Installation
npm install @bemoje/arr-clone
npm install --save @bemoje/arr-clone
npm install --save-dev @bemoje/arr-clone
Usage
import arrClone from '@bemoje/arr-clone'
/**
* compares strict equality of each element in a shallow comparison.
*/
function shallowCompareArrays(arr1, arr2) {
for (let i = 0; i < arr1.length; i++) {
if (arr1[i] !== arr2[i]) {
return false
}
}
return true
}
const arr = [1, 2]
const cloned = arrClone(arr)
/**
* ALL ELEMENTS ARE THE SAME
*/
shallowCompareArrays(arr, cloned)
//=> true
/**
* DO NOT REFER TO THE SAME OBJECT, IE. A "CLONE"
*/
arr === cloned
//=> false
Tests
Uses Jest to test module functionality. Run tests to get coverage details.
npm run test
API
arrClone
Shallow clone of provided array, 'arr'.
Parameters
arr
Array The array to clone
Returns
Array The cloned array