taesik

contain_all_rotation 본문

functions and trick/typescript_javascript

contain_all_rotation

taesikk 2022. 1. 23. 14:31

contain_all_rots(strng, arr) (or containAllRots or contain-all-rots):

  • a boolean true if all rotations of strng are included in arr (C returns 1)
  • false otherwise (C returns 0)
더보기
export function containAllRots($: string, arr: string[]): boolean {
  arr = arr.map(e => e.toLowerCase());
  const arr$ = Array.from({length: $.length}, x => $.toLowerCase())
      .map((el, i)=> el.slice(i)+el.slice(0,i))
  return arr$.every(e => arr.includes(e))
}

 

<rotaition>

.map((element, index)=>element.slice(index)+element.slice(0,index))