mirror of
https://github.com/navidrome/navidrome.git
synced 2025-05-15 09:36:38 +03:00
21 lines
414 B
JavaScript
21 lines
414 B
JavaScript
/* intersperse: Return an array with the separator interspersed between
|
|
* each element of the input array.
|
|
*
|
|
* > _([1,2,3]).intersperse(0)
|
|
* [1,0,2,0,3]
|
|
*
|
|
* From: https://stackoverflow.com/a/23619085
|
|
*/
|
|
export const intersperse = (arr, sep) => {
|
|
if (arr.length === 0) {
|
|
return []
|
|
}
|
|
|
|
return arr.slice(1).reduce(
|
|
function (xs, x, i) {
|
|
return xs.concat([sep, x])
|
|
},
|
|
[arr[0]],
|
|
)
|
|
}
|