Alphabet Array Golfed
l=[]
for(i=26;i--;)l[i]=(10+i).toString(36)
console.log(l)
A nasty golfed way to fill an array with letters a-z.
I usually do (as seen in another post):
let letters = 'abcdefghijklmopqrstuvwxyz'.split``
l=[]
for(i=26;i--;)l[i]=(10+i).toString(36)
console.log(l)
A nasty golfed way to fill an array with letters a-z.
I usually do (as seen in another post):
let letters = 'abcdefghijklmopqrstuvwxyz'.split``
document.body.innerHTML = '<pre>'+`n2zh2
f8l2b2l8
b8pep8
7cpepc
5ijiji
3yyq
0
0
0
3yyq
5afy8fa
98f69a96f8
f4f2d6d2f4`.replace(/./g,c=>'* '[(n=parseInt(c,36))&1].repeat(n/2||49))
* * **** * * **** **** ******* **** ****** ******* ****** ********* ********* ********* *********************************************** ************************************************* ************************************************* ************************************************* *********************************************** ***** ********************* ***** **** *** ***** *** **** ** * *** * **
Fun js codegolf answer from user arnauld… Whole thread is very fun…
d = document
b = d.body
b.style.margin = 0
with (b.appendChild(
Object.assign(d.createElement`canvas`, {
width: innerWidth,
height: innerHeight,
})
).getContext`2d`) {
mx = 0
my = 0
onresize = _ => {
canvas.width = innerWidth
canvas.height = innerHeight
}
onpointermove = e => {
mx = e.clientX,
my = e.clientY
}
r = 0
loop = () => {
save()
globalCompositeOperation = 'hard-light'
translate(innerWidth / 2, innerHeight / 2)
rotate(r += .02)
translate(-innerWidth / 2, -innerHeight / 2)
fillStyle = 'rgba(55, 55, 55, .01)'
fillRect(0, 0, innerWidth, innerHeight)
fillStyle = 'rgba(116, 196, 221, .02)'
fillRect(0, my, innerWidth, 20);
fillStyle = 'rgba(255, 255, 255, .02)'
fillRect(mx, 0, 20, innerHeight);
fillStyle = 'rgba(0, 0, 0, .03)'
fillRect(0, innerHeight - my, innerWidth, 20);
fillStyle = 'rgba(116, 196, 221, .02)'
fillRect(innerWidth - mx, 0, 20, innerHeight);
restore()
requestAnimationFrame(loop)
}
loop()
}
Speed coded mouse toy…
!0 // true
!1 // false
1/0 // Infinity
0[0] // undefined (any digit works)
This is from user Isiah Meadows on the codegolf stackexchange…
r={valueOf:_=>Math.random()}
console.log(+r)
console.log(+r)
console.log(+r)
Use valueOf
to shorten function calls. I learned this trick over at stackexchange codegolf here from user cyoce.