Códigos Fuente de JavaScript

Mostrando del 71 al 80 de 916 registros
Imágen de perfil
Val: 2.288
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Poner en mayúsculas la primera letra de todas las palabras de una frase con JavaScript


JavaScript

Publicado el 24 de Marzo del 2021 por Katas (200 códigos)
993 visualizaciones desde el 24 de Marzo del 2021
Dos función para poner la primera letra de cada palabra de una cadena en mayúsculas.

La primer función mantiene los espacios en blando entre las palabras
1
2
3
4
capitalizeEachWord1(""); // ""
capitalizeEachWord1("a"); // "A"
capitalizeEachWord1("la casa azul"); // "La Casa Azul"
capitalizeEachWord1("la     casa    azul"); // "La     Casa    Azul"

La segunda versión, solo mantiene un espacio entre las palabras, eliminando el resto de ellos
1
2
3
4
capitalizeEachWord2(""); // ""
capitalizeEachWord2("a"); // "A"
capitalizeEachWord2("la casa azul"); // "La Casa Azul"
capitalizeEachWord2("la     casa    azul"); // "La Casa Azul"


Si deseas poner en mayúsculas solo la primera letra: https://www.lawebdelprogramador.com/codigo/JavaScript/6968-Poner-en-mayusculas-la-primera-letra-de-una-frase-con-JavaScript.html
Imágen de perfil
Val: 2.288
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Obtener la fecha del día siguiente a una Date() especificada


JavaScript

Publicado el 23 de Marzo del 2021 por Katas (200 códigos)
1.018 visualizaciones desde el 23 de Marzo del 2021
Función que devuelve un objeto Date con el siguiente día de la fecha recibida.
Si no se recibe un valor de tipo Date devuelve la fecha actual pero de mañana.

1
2
dt=new Date(2020, 10, 10, 10, 10, 10);
newDt=getNextDay(dt); // Wed Nov 11 2020 10:10:10

NOTA: Hay que tener en cuenta que el mes va del 0 al 11
Imágen de perfil
Val: 2.288
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Obtener la fecha de la semana siguiente a una Date() especificada


JavaScript

Publicado el 23 de Marzo del 2021 por Katas (200 códigos)
939 visualizaciones desde el 23 de Marzo del 2021
Función que devuelve un objeto Date con la siguiente semana de la fecha recibida.
Si no se recibe un valor de tipo Date devuelve la fecha actual en la siguiente semana.

1
2
dt=new Date(2020, 10, 10, 10, 10, 10);
newDt=getNextWeek(dt); // Tue Nov 17 2020 10:10:10

NOTA: Hay que tener en cuenta que el mes va del 0 al 11
Imágen de perfil
Val: 2.288
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Obtener la fecha del siguiente mes a una Date() especificada


JavaScript

Publicado el 23 de Marzo del 2021 por Katas (200 códigos)
666 visualizaciones desde el 23 de Marzo del 2021
Función que devuelve un objeto Date con el siguiente mes de la fecha recibida.
Si no se recibe un valor de tipo Date devuelve la fecha actual en el siguiente mes.

1
2
dt=new Date(2020, 10, 10, 10, 10, 10);
newDt=getNextMonth(dt); // Thu Dec 10 2020 10:10:10

NOTA: Hay que tener en cuenta que el mes va del 0 al 11
Imágen de perfil
Val: 2.288
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Obtener la fecha del siguiente año a una Date() especificada


JavaScript

Publicado el 23 de Marzo del 2021 por Katas (200 códigos)
754 visualizaciones desde el 23 de Marzo del 2021
Función que devuelve un objeto Date con el siguiente año de la fecha recibida.
Si no se recibe un valor de tipo Date devuelve la fecha actual en el siguiente año.

1
2
dt=new Date(2020, 10, 10, 10, 10, 10);
newDt=getNextYear(dt); // Wed Nov 10 2021 10:10:10

NOTA: Hay que tener en cuenta que el mes va del 0 al 11
Imágen de perfil
Val: 2.288
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Obtener los n valores mas grandes de un array con JavaScript


JavaScript

estrellaestrellaestrellaestrellaestrella(2)
Publicado el 22 de Marzo del 2021 por Katas (200 códigos)
3.976 visualizaciones desde el 22 de Marzo del 2021
Función para devolver la cantidad de valores mas grandes de un array.

La función lo que haces es hacer una copia del array con arr.slice() (si no se hace una copia, el array se pasa por referencia, y se modificaría el original).
Posteriormente, se ordena con sort() y se invierten los valores con reverse().
Finalmente obtenemos la cantidad de valores deseados con splice().

1
2
3
4
5
6
const arr=[1,6,3,2,8,4,9,5];
 
mayores(arr, 1); // [9]
mayores(arr, 3); // [9, 8, 6]
mayores(arr, 5); // [9, 8, 6, 5, 4]
mayores(arr, 100); // [9, 8, 6, 5, 4, 3, 2, 1]
Imágen de perfil
Val: 2.288
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Obtener el valor de cualquier estilo de un elemento


JavaScript

Publicado el 19 de Marzo del 2021 por Katas (200 códigos)
690 visualizaciones desde el 19 de Marzo del 2021
Este código muestra como obtener cualquier valor de los posibles estilos que puede tener un elemento.

En este ejemplo, estos son los estilos de nuestro <div>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
-webkit-writing-mode -> horizontal-tb
-webkit-user-modify -> read-only
-webkit-user-drag -> auto
-webkit-text-stroke-width -> 0px
-webkit-text-stroke-color -> rgb(0, 0, 0)
-webkit-text-security -> none
-webkit-text-orientation -> vertical-right
-webkit-text-fill-color -> rgb(0, 0, 0)
-webkit-text-emphasis-style -> none
-webkit-text-emphasis-position -> over right
-webkit-text-emphasis-color -> rgb(0, 0, 0)
-webkit-text-decorations-in-effect -> none
-webkit-text-combine -> none
-webkit-tap-highlight-color -> rgba(0, 0, 0, 0.18)
-webkit-rtl-ordering -> logical
-webkit-print-color-adjust -> economy
-webkit-mask-size -> auto
-webkit-mask-repeat -> repeat
-webkit-mask-position -> 0% 0%
-webkit-mask-origin -> border-box
-webkit-mask-image -> none
-webkit-mask-composite -> source-over
-webkit-mask-clip -> border-box
-webkit-mask-box-image-width -> auto
-webkit-mask-box-image-source -> none
-webkit-mask-box-image-slice -> 0 fill
-webkit-mask-box-image-repeat -> stretch
-webkit-mask-box-image-outset -> 0
-webkit-mask-box-image -> none
-webkit-locale -> auto
-webkit-line-clamp -> none
-webkit-line-break -> auto
-webkit-hyphenate-character -> auto
-webkit-highlight -> none
-webkit-font-smoothing -> auto
-webkit-box-reflect -> none
-webkit-box-pack -> start
-webkit-box-orient -> horizontal
-webkit-box-ordinal-group -> 1
-webkit-box-flex -> 0
-webkit-box-direction -> normal
-webkit-box-decoration-break -> slice
-webkit-box-align -> stretch
-webkit-border-vertical-spacing -> 0px
-webkit-border-image -> none
-webkit-border-horizontal-spacing -> 0px
-webkit-app-region -> none
zoom -> 1
z-index -> auto
y -> 0px
x -> 0px
writing-mode -> horizontal-tb
word-spacing -> 0px
word-break -> normal
will-change -> auto
width -> 1247px
widows -> 2
white-space -> normal
visibility -> visible
vertical-align -> baseline
vector-effect -> none
user-select -> auto
unicode-bidi -> normal
transition-timing-function -> ease
transition-property -> all
transition-duration -> 0s
transition-delay -> 0s
transform-style -> flat
transform-origin -> 623.5px 612px
transform -> none
touch-action -> auto
top -> auto
text-underline-position -> auto
text-transform -> none
text-size-adjust -> auto
text-shadow -> none
text-rendering -> auto
text-overflow -> clip
text-indent -> 0px
text-decoration-style -> solid
text-decoration-skip-ink -> auto
text-decoration-line -> none
text-decoration-color -> rgb(0, 0, 0)
text-decoration -> none solid rgb(0, 0, 0)
text-anchor -> start
text-align-last -> auto
text-align -> start
table-layout -> auto
tab-size -> 8
stroke-width -> 1px
stroke-opacity -> 1
stroke-miterlimit -> 4
stroke-linejoin -> miter
stroke-linecap -> butt
stroke-dashoffset -> 0px
stroke-dasharray -> none
stroke -> none
stop-opacity -> 1
stop-color -> rgb(0, 0, 0)
speak -> normal
shape-rendering -> auto
shape-outside -> none
shape-margin -> 0px
shape-image-threshold -> 0
scroll-padding-inline-start -> auto
scroll-padding-inline-end -> auto
scroll-padding-block-start -> auto
scroll-padding-block-end -> auto
scroll-margin-inline-start -> 0px
scroll-margin-inline-end -> 0px
scroll-margin-block-start -> 0px
scroll-margin-block-end -> 0px
scroll-behavior -> auto
ry -> auto
rx -> auto
ruby-position -> over
row-gap -> normal
right -> auto
resize -> none
r -> 0px
position -> static
pointer-events -> auto
perspective-origin -> 623.5px 1098px
perspective -> none
paint-order -> normal
padding-top -> 0px
padding-right -> 0px
padding-left -> 0px
padding-inline-start -> 0px
padding-inline-end -> 0px
padding-bottom -> 0px
padding-block-start -> 0px
padding-block-end -> 0px
overscroll-behavior-inline -> auto
overscroll-behavior-block -> auto
overflow-y -> visible
overflow-x -> visible
overflow-wrap -> normal
overflow-anchor -> auto
outline-width -> 0px
outline-style -> none
outline-offset -> 0px
outline-color -> rgb(0, 0, 0)
orphans -> 2
order -> 0
opacity -> 1
offset-rotate -> auto 0deg
offset-path -> none
offset-distance -> 0px
object-position -> 50% 50%
object-fit -> fill
mix-blend-mode -> normal
min-width -> 0px
min-inline-size -> 0px
min-height -> 0px
min-block-size -> 0px
max-width -> none
max-inline-size -> none
max-height -> none
max-block-size -> none
mask-type -> luminance
marker-start -> none
marker-mid -> none
marker-end -> none
margin-top -> 0px
margin-right -> 0px
margin-left -> 0px
margin-inline-start -> 0px
margin-inline-end -> 0px
margin-bottom -> 0px
margin-block-start -> 0px
margin-block-end -> 0px
list-style-type -> disc
list-style-position -> outside
list-style-image -> none
line-height -> normal
line-break -> auto
lighting-color -> rgb(255, 255, 255)
letter-spacing -> normal
left -> auto
justify-self -> auto
justify-items -> normal
justify-content -> normal
isolation -> auto
inset-inline-start -> auto
inset-inline-end -> auto
inset-block-start -> auto
inset-block-end -> auto
inline-size -> 1247px
image-rendering -> auto
image-orientation -> from-image
hyphens -> manual
height -> 3456px
grid-template-rows -> none
grid-template-columns -> none
grid-template-areas -> none
grid-row-start -> auto
grid-row-end -> auto
grid-column-start -> auto
grid-column-end -> auto
grid-auto-rows -> auto
grid-auto-flow -> row
grid-auto-columns -> auto
font-weight -> 400
font-variant-numeric -> normal
font-variant-ligatures -> normal
font-variant-east-asian -> normal
font-variant-caps -> normal
font-variant -> normal
font-style -> normal
font-stretch -> 100%
font-size -> 16px
font-optical-sizing -> auto
font-kerning -> auto
font-family -> "Times New Roman"
flood-opacity -> 1
flood-color -> rgb(0, 0, 0)
float -> none
flex-wrap -> nowrap
flex-shrink -> 1
flex-grow -> 0
flex-direction -> row
flex-basis -> auto
filter -> none
fill-rule -> nonzero
fill-opacity -> 1
fill -> rgb(0, 0, 0)
empty-cells -> show
dominant-baseline -> auto
display -> block
direction -> ltr
d -> none
cy -> 0px
cx -> 0px
cursor -> auto
content -> normal
column-width -> auto
column-span -> none
column-rule-width -> 0px
column-rule-style -> none
column-rule-color -> rgb(0, 0, 0)
column-gap -> normal
column-count -> auto
color-rendering -> auto
color-interpolation-filters -> linearrgb
color-interpolation -> srgb
color -> rgb(0, 0, 0)
clip-rule -> nonzero
clip-path -> none
clip -> auto
clear -> none
caret-color -> rgb(0, 0, 0)
caption-side -> top
buffered-rendering -> auto
break-inside -> auto
break-before -> auto
break-after -> auto
box-sizing -> content-box
box-shadow -> none
bottom -> auto
border-top-width -> 0px
border-top-style -> none
border-top-right-radius -> 0px
border-top-left-radius -> 0px
border-top-color -> rgb(0, 0, 0)
border-right-width -> 0px
border-right-style -> none
border-right-color -> rgb(0, 0, 0)
border-left-width -> 0px
border-left-style -> none
border-left-color -> rgb(0, 0, 0)
border-inline-start-width -> 0px
border-inline-start-style -> none
border-inline-start-color -> rgb(0, 0, 0)
border-inline-end-width -> 0px
border-inline-end-style -> none
border-inline-end-color -> rgb(0, 0, 0)
border-image-width -> 1
border-image-source -> none
border-image-slice -> 100%
border-image-repeat -> stretch
border-image-outset -> 0
border-collapse -> separate
border-bottom-width -> 0px
border-bottom-style -> none
border-bottom-right-radius -> 0px
border-bottom-left-radius -> 0px
border-bottom-color -> rgb(0, 0, 0)
border-block-start-width -> 0px
border-block-start-style -> none
border-block-start-color -> rgb(0, 0, 0)
border-block-end-width -> 0px
border-block-end-style -> none
border-block-end-color -> rgb(0, 0, 0)
block-size -> 5292px
baseline-shift -> 0px
background-size -> auto
background-repeat -> repeat
background-position -> 0% 0%
background-origin -> padding-box
background-image -> url("http://localhost/test/image.jpg")
background-color -> rgba(0, 0, 0, 0)
background-clip -> border-box
background-blend-mode -> normal
background-attachment -> scroll
backface-visibility -> visible
backdrop-filter -> none
appearance -> none
animation-timing-function -> ease
animation-play-state -> running
animation-name -> none
animation-iteration-count -> 1
animation-fill-mode -> none
animation-duration -> 0s
animation-direction -> normal
animation-delay -> 0s
alignment-baseline -> auto
align-self -> auto
align-items -> normal
align-content -> normal
Imágen de perfil
Val: 3.506
Oro
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Guardar los valores introducidos en un array y devolver, media, máximo, mínimo, par, impar, ...


JavaScript

estrellaestrellaestrellaestrellaestrella(2)
Actualizado el 11 de Marzo del 2021 por Joel (150 códigos) (Publicado el 12 de Marzo del 2020)
4.603 visualizaciones desde el 12 de Marzo del 2020
Código de ejemplo que muestra como va obteniendo los valores recibidos por el usuario y los va guardando en un arrays, y ir mostrando los elementos pares, impares, la suma de los elementos pares y impares, suma total de todos los valores, valor máximo y valor mínimo.

calculos-con-numeros