Created
May 6, 2017 01:03
-
-
Save Woodsphreaker/ffb54553223114b0611e00c48ede000f to your computer and use it in GitHub Desktop.
sliceArray.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr = [1, 2, 3, 4, 5] | |
const pos = 2 | |
const el = [10,11,12,13] | |
const slice = (arr) => (start) => (end) => [].concat(arr.slice(start, end)) | |
const value = (el) => [].concat(el) | |
const insert = (arr) => (pos) => (el) => { | |
return [...slice(arr)(0)(pos), ...value(el), ...slice(arr)(pos)()] | |
} | |
const insertArr = insert(arr) | |
const insertPos = insertArr(pos) | |
const insertEl = insertPos(el) | |
const result = insertEl | |
console.log(result) //[ 1, 2, 10, 11, 12, 13, 3, 4, 5 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment