Feast 2.0!
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

40 строки
1015 B

  1. import Vue from 'vue'
  2. import App from './App.vue'
  3. declare global {
  4. interface Array<T> {
  5. joinGeneral (item: T, endItem: T|null): Array<T>;
  6. /* eslint-disable-next-line */
  7. unique (predicate: (elem: T) => any): Array<T>;
  8. }
  9. }
  10. /* eslint-disable-next-line */
  11. Array.prototype.joinGeneral = function (item, endItem = null) {
  12. if (endItem === null) {
  13. return this.slice(0, -1).flatMap(x => [x, item]).concat(this.slice(-1))
  14. } else {
  15. return this.slice(0, -2).flatMap(x => [x, item]).concat(this.slice(-2, -1).flatMap(x => [x, endItem])).concat(this.slice(-1))
  16. }
  17. }
  18. /* eslint-disable-next-line */
  19. Array.prototype.unique = function<T> (predicate: (elem: T) => any): Array<T> {
  20. const set = new Set()
  21. const result: Array<T> = [] as T[]
  22. this.forEach(elem => {
  23. const predResult = predicate(elem)
  24. if (!set.has(predResult)) {
  25. set.add(predResult)
  26. result.push(elem)
  27. }
  28. })
  29. return result
  30. }
  31. Vue.config.productionTip = false
  32. new Vue({
  33. render: h => h(App)
  34. }).$mount('#app')