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

41 строка
1.1 KiB

  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. // if there is no predicate, just use the identity function
  24. const predResult = (predicate ?? (x => x))(elem)
  25. if (!set.has(predResult)) {
  26. set.add(predResult)
  27. result.push(elem)
  28. }
  29. })
  30. return result
  31. }
  32. Vue.config.productionTip = false
  33. new Vue({
  34. render: h => h(App)
  35. }).$mount('#app')