// export function moveToTop(index:number,array:any[]){
//     const indexItemBefore = index - 1
//     if(indexItemBefore == -1)return array;
//     const currentItem = array[index]
//     array[index] = array[indexItemBefore]
//     array[indexItemBefore] = currentItem
//     return array

// }
// export function moveToBottom(index:number,array:any[]){
//     const indexItemAfter = index + 1 
//     if(indexItemAfter == array.length)return array;
//     const currentItem = array[index]
//     array[index] = array[indexItemAfter]
//     array[indexItemAfter] = currentItem
//     return array
// }

function swapImmutable<T>(arr: T[], i: number, j: number): T[] {
  if (i === j) return arr.slice();
  const copy = arr.slice();
  [copy[i], copy[j]] = [copy[j], copy[i]];
  return copy;
}

export function moveToTop(index: number, array: any[]) {
  if (index <= 0) return array.slice();
  return swapImmutable(array, index, index - 1);
}

export function moveToBottom(index: number, array: any[]) {
  if (index >= array.length - 1) return array.slice();
  return swapImmutable(array, index, index + 1);
}

export const uid = () => Date.now().toString() + Math.random().toString(36).slice(2,9);
