1+ // © 2021-2025 by César Andres Arcila Buitrago
2+
3+ const console = {
4+ messages : [ ] ,
5+ log : function ( message ) {
6+ this . messages . push ( "LOG: " + message ) ;
7+ } ,
8+ info : function ( message ) {
9+ this . messages . push ( "INFO: " + message ) ;
10+ } ,
11+ warn : function ( message ) {
12+ this . messages . push ( "WARN: " + message ) ;
13+ } ,
14+ error : function ( message ) {
15+ this . messages . push ( "ERROR: " + message ) ;
16+ }
17+ }
18+
19+ function getConsole ( ) {
20+ return console . messages . join ( '\n' ) ;
21+ }
22+
23+ String . prototype . substr = function ( start , length ) {
24+ if ( start < 0 ) {
25+ start = this . length + start ;
26+ if ( start < 0 ) start = 0 ;
27+ }
28+ if ( length === undefined ) {
29+ return this . substring ( start ) ;
30+ }
31+ if ( length < 0 ) {
32+ return '' ;
33+ }
34+ return this . substring ( start , start + length ) ;
35+ }
36+ /*
37+ // Implementación de Array.prototype.findIndex si no existe
38+ if (!Array.prototype.findIndex) {
39+ Array.prototype.findIndex = function(predicate) {
40+ if (this == null) {
41+ throw new TypeError('Array.prototype.findIndex called on null or undefined');
42+ }
43+ if (typeof predicate !== 'function') {
44+ throw new TypeError('predicate must be a function');
45+ }
46+
47+ const list = Object(this);
48+ const length = list.length >>> 0;
49+ const thisArg = arguments[1];
50+
51+ for (let i = 0; i < length; i++) {
52+ if (i in list && predicate.call(thisArg, list[i], i, list)) {
53+ return i;
54+ }
55+ }
56+
57+ return -1;
58+ };
59+ }
60+
61+ // Implementación de Array.prototype.find si no existe
62+ if (!Array.prototype.find) {
63+ Array.prototype.find = function(predicate) {
64+ if (this == null) {
65+ throw new TypeError('Array.prototype.find called on null or undefined');
66+ }
67+ if (typeof predicate !== 'function') {
68+ throw new TypeError('predicate must be a function');
69+ }
70+
71+ const list = Object(this);
72+ const length = list.length >>> 0;
73+ const thisArg = arguments[1];
74+
75+ for (let i = 0; i < length; i++) {
76+ if (i in list && predicate.call(thisArg, list[i], i, list)) {
77+ return list[i];
78+ }
79+ }
80+
81+ return undefined;
82+ };
83+ }
84+
85+ // Implementación de Array.prototype.splice si no existe o no funciona correctamente
86+ if (!Array.prototype.splice || typeof Array.prototype.splice !== 'function') {
87+ Array.prototype.splice = function(start, deleteCount) {
88+ if (this == null) {
89+ throw new TypeError('Array.prototype.splice called on null or undefined');
90+ }
91+
92+ const array = Object(this);
93+ const len = array.length >>> 0;
94+
95+ // Convertir start a un entero
96+ start = parseInt(start, 10) || 0;
97+ if (start < 0) {
98+ start = Math.max(len + start, 0);
99+ } else {
100+ start = Math.min(start, len);
101+ }
102+
103+ // Convertir deleteCount a un entero
104+ deleteCount = parseInt(deleteCount, 10) || 0;
105+ deleteCount = Math.max(0, Math.min(deleteCount, len - start));
106+
107+ // Elementos a insertar
108+ const itemCount = arguments.length - 2;
109+ const removed = new Array(deleteCount);
110+
111+ // Guardar elementos eliminados
112+ for (let i = 0; i < deleteCount; i++) {
113+ removed[i] = array[start + i];
114+ }
115+
116+ // Calcular cuántos elementos quedarán después de la operación
117+ const newLen = len - deleteCount + itemCount;
118+
119+ // Si hay más elementos a insertar que a eliminar, mover elementos existentes
120+ if (itemCount > deleteCount) {
121+ for (let i = len - 1; i >= start + deleteCount; i--) {
122+ array[i + (itemCount - deleteCount)] = array[i];
123+ }
124+ }
125+ // Si hay menos elementos a insertar que a eliminar, mover elementos existentes
126+ else if (itemCount < deleteCount) {
127+ for (let i = start + deleteCount; i < len; i++) {
128+ array[i - (deleteCount - itemCount)] = array[i];
129+ }
130+ // Ajustar la longitud del array
131+ array.length = newLen;
132+ }
133+
134+ // Insertar nuevos elementos
135+ for (let i = 0; i < itemCount; i++) {
136+ array[start + i] = arguments[i + 2];
137+ }
138+
139+ return removed;
140+ };
141+ }
142+ */
0 commit comments