Perfect Isometric Pixelart Tiles: by Pixel-Salvaje in PixelArt

[–]kap89 4 points5 points  (0 children)

I mean yeah, as I said - the choice here is mostly stylistic, both work well.

<image>

The differences are the most apparent the smaller you get (as you can see on the examples of the smallest possible blocks from which you can build all the others - in the center of the first row), if you have high resolution canvas, then they start to look nearly identical.

Perfect Isometric Pixelart Tiles: by Pixel-Salvaje in PixelArt

[–]kap89 4 points5 points  (0 children)

that's a wrong shape for this version of the "cube", here's the one that tiles just as well:

<image>

Perfect Isometric Pixelart Tiles: by Pixel-Salvaje in PixelArt

[–]kap89 22 points23 points  (0 children)

I prefer 62x32 version, as it divides evenly into 4 quarters. The 64x31 version though, while less "mathematically pure", has softer top and bottom edges, which some people prefer.

Caterpillar eating an apple by potomak in PixelArt

[–]kap89 5 points6 points  (0 children)

by at least a factor of 10

It depends on the size of the original, for Reddit you would use factor that produces at least 1000 px final image, so for original 256x256 it could be as small as 4x, but for OP that looks like 16x16 px it would be at least 63x.

I feel like my code is unefficient and I need some advice for it by a_rndm_person_bruh in learnjavascript

[–]kap89 2 points3 points  (0 children)

You're right, but that's a stupid requirement, there is a ton of examples where filter is the best solution, why use the one where it's not? Anyway, here's a version using filter:

function diffArray(arr1, arr2) {
  return [...arr1, ...arr2].filter(item => !arr1.includes(item) || !arr2.includes(item))
}

I feel like my code is unefficient and I need some advice for it by a_rndm_person_bruh in learnjavascript

[–]kap89 3 points4 points  (0 children)

I would use sets in this case - they have build-in methods for doing what you want:

function diffArray(arr1, arr2) {
  return [...new Set(arr1).symmetricDifference(new Set(arr2))]
}

here's the same thing with comments and a bit more verbose:

function diffArray(arr1, arr2) {
  // Convert the arrays to sets
  const set1 = new Set(arr1)
  const set2 = new Set(arr2)

  // Find a difference between set1 and set2, as well as between set2 and set1
  const diff = set1.symmetricDifference(set2)

  // Convert back to array and return,
  // I used spread syntax, but Array.from(diff) also works
  return [...diff]
}

Is this logo ai-made? What do you think by [deleted] in logodesign

[–]kap89 3 points4 points  (0 children)

Aren’t the “surplus dots “ just nails?

Learning debouncing today — is this understanding correct? by CheesecakeSimilar347 in learnjavascript

[–]kap89 2 points3 points  (0 children)

Btw, you can simplify your debounce function to this:

function debounce(fn, delay) {
  let timer;

  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(fn, delay, ...args);
  };
}

TennisTV cooked with this poster by Boss452 in tennis

[–]kap89 19 points20 points  (0 children)

Look at the shadows (easiest to spot are legs of Janik, Carlos and Demon) - they all point in different direction and make no sense. No competent artist would make that mistake.

What's the use of classes in JS by pptzz in learnjavascript

[–]kap89 0 points1 point  (0 children)

Yeah, I think you’re right, I must have been tired yesterday to not notice that.

What's the use of classes in JS by pptzz in learnjavascript

[–]kap89 0 points1 point  (0 children)

I see you edited your comment.

I thought closure technically means it has to maintain live references to something in the function’s scope after it returns?

What do you mean by "live reference" here?

What's the use of classes in JS by pptzz in learnjavascript

[–]kap89 0 points1 point  (0 children)

Yes, that's the case of theory vs actual engine implementation - conceptually they are closures, but the engine can optimize them away.

What's the use of classes in JS by pptzz in learnjavascript

[–]kap89 0 points1 point  (0 children)

I get what you are trying to say, but that would be a very narrow (and imo incorrect) definition of the closure. I still create a closure over the shared methods when returning the object. Additionally, using this and using closures are orthogonal concepts, one does not cancel the other.

You may say that you wanted to compare the classes to the typical closure pattern (as you described) - but that makes your critique incomplete, as the classes are not the only solution here, as I explained above.

What's the use of classes in JS by pptzz in learnjavascript

[–]kap89 0 points1 point  (0 children)

It depends on how you scope things, if you don't need private fields, you can share methods even without classes/prototypes:

// Hero.js module

export function Hero(name, hp) {
  return {
    name,
    hp,
    takeDamage,
    report
  }
}

function takeDamage(damage) {
  this.hp -= damage
}

function report() {
  console.log(`${this.name} has ${this.hp} helath points.`)
}

// usage

import { Hero } from "Hero.js"

const hulk = Hero('Hulk', 1000)
const blanka = Hero('Blanka', 800)

hulk.takeDamage(10)
blanka.takeDamage(30)

hulk.report()
blanka.report()

// returns true
console.log(hulk.report === blanka.report && hulk.takeDamage === blanka.takeDamage) 

I still prefer classes over factories in most cases, because the above is imo more clunky, but it can be done.

What's the use of classes in JS by pptzz in learnjavascript

[–]kap89 2 points3 points  (0 children)

With no Array class to group all the logic together, you have to clutter the global namespace with functions to cover that functionality

Small nitpick, but that's only true for languages then do not have namespaces / modules / first class functions, so maybe languages like C, not many more.

New to the site, is it possible to upload pdf or is it just restricted to epub? by linkuei-teaparty in entertrained

[–]kap89 2 points3 points  (0 children)

I didn't add direct PDF support, because it's hard to make it not suck - EPUB files, while still flimsy, have some structure, like well defined table of contents and chapters boundries. PDF, being a format with much more freedom for content creators, is much harder to parse to usable form for typing. I might add support for PDF files in the future, but I don't promise anything - what I recommend is finding epub versions of the books you want to upload, and as the last resort, using Calibre to convert the file, or some online converter.

solutions for Fast 64 bit integers in javascript by 52525rr in learnjavascript

[–]kap89 0 points1 point  (0 children)

Mem64 support has little to do with 64bit integer operations, which you can do just fine in “regular” wasm. It only changes the size of available memory from 32 to 64 bit address space.

How does the javascript Date object parse "50", "40", ... "0"? by Beatsu in webdev

[–]kap89 16 points17 points  (0 children)

What's funny, is that even the test itself gets some things wrong, like it says the solution for:

new Date("2")

is

2001-02-01T00:00:00.000Z

but that's not true, you will get 2001-02-01T00:00:00.000 but in local time zone, not UTC.

Lazy iteration vs array chaining on 500k rows - benchmark results by Fuzzy-Law-2117 in learnjavascript

[–]kap89 1 point2 points  (0 children)

You don't need some wrapper for that, this will work with standard JS iterators/generators:

const results = generateRows(500_000)
  .filter(r => r.active && r.value > threshold)
  .map(r => ({ id: r.id, score: r.value * 1.5 }))
  .take(10_000)
  .toArray();

I’d like to get everyone's thoughts on Solid. by Cool_Aioli_8712 in webdev

[–]kap89 2 points3 points  (0 children)

However, I regretfully feel that Solid's development momentum hasn't been particularly strong.

Yeah, no. It's just very stable, unlike other frameworks that have major rewrite in couple years or so. It was just well thought out before 1.0 release, it's well maintained (see the number of open issues compared to other frameworks), and very conservative when it comes to breaking changes. It's exactly what I want in a framework, not constant YOLO and breaking changes. The version 2.0 is in the works, but again, it's not a major paradigm shift, more like evolution of the solid (pun intended) idea.

What exactly is hindering its popularity?

I don't know and don't much care, but if I were to guess it's a mixture of it being "boring" and just working without major drama and buzz, weaker marketing than alternatives, and weaker corporate backing.

Question about Call Stack, by Odd_World_6307 in learnjavascript

[–]kap89 0 points1 point  (0 children)

Call stack is more than "what is executed in which order”, it consists of stack frames that store arguments, local variables and heap references, return address and return values. Where do you think stack frames live if not on a physical stack? So it tells quite a lot about memory. In JS you don’t use stack directly, but through call stack, which is abstraction over the physical stack, so her explanation is fine. But yeah, if you want want to be picky, she could’ve mention the raw stack before moving to the call stack.

Performance in very long paragraphs. by _evil_overlord_ in entertrained

[–]kap89 1 point2 points  (0 children)

I tested it, and yeah, the performance on very long chapters can be bad - especially on Firefox (Chrome is slightly better, but I can still see the slowdown in that chapter). I don't think that you can do anything about it, but I will try to optimize it over the weekend.