Skip to content

Instantly share code, notes, and snippets.

@og24715
Created July 24, 2018 05:59
Show Gist options
  • Save og24715/2e701d22a104b38312d161e913844602 to your computer and use it in GitHub Desktop.
Save og24715/2e701d22a104b38312d161e913844602 to your computer and use it in GitHub Desktop.
Twitter で新しくツイートを取得する時に重複なしにがっちゃんこする
const newList = [1, 2, 3, 4, 5]
const list = [4, 5, 6, 7, 8]
const endIndex = newList.findIndex(item => item === list[0]) // -> 3

const diff = newList.slice(0, endIndex === -1 ? undefined : endIndex)

console.log([...diff, ...list]) // -> [1, 2, 3, 4, 5, 6, 7, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment