Skip to content

Tag: math

Generate random 6 characters based on input

Generate random 6 characters based on input. Like I want to turn 1028797107357892628 into j4w8p. Or 102879708974181177 into lg36k but I want it to be consistant. Like whenever I feed 1028797107357892628 in, it should always spit out j4w8p. Is this possible? (Without a database if possible.) I know how to generate random 6 characters but I dont know how to

Only half of array gets raised to power

I wanted to create binary to decimal calculator. When i tried to console log both of arrays (binary is array of 0’s and 1’s, binarypos is array of numbers that are powers of 2. Screenshot Then i created simpler version, made in console so chance of making a mistake lowered to zero. But the bug appears again! I want it

Calculate width of hexagons in a field

I am drawing a hexagonal grid using javascript and svg. The grid needs to have a fixed width (let’s say, of 1000px). The dimensions of the grid can differ, but I have that information (the columns and rows). I have written a function that given a hexagons ‘bounding box’ width (the height is a factor 0.8660254 of the width), will

Reverse Isometric Projection in Javascript

I have a function which converts some 3D coords (x, y, z) into a position in the screen (width, height), with an isometric perspective (true isometric, not dimetric). So, for better clarification, here we have the blue lines, which represents the 2D Screen, and the black lines, which represents the 3D isometric space: The above function works fine. If I

Percetange calculation wrong result

I want to calculate the percentage of a minute from a given number of hours. So let’s say I have 2 hours. That’s 2*60 minutes. And I want to know how much percent does 1 minute take from 2 hours. The value should be 0.833, because 0.833 * (2*60) = 100%. But how do I get this 0.833 number? (hours

Convert 45 to 1 and 345 to 2 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 9 months ago. Improve this question I’m building a carousel with a swiping limit exceeding both left and right of 45px on each item has 300px width I wonder How to

MYR Currency Rounding

Looking for help in rounding the money to the nearest 0.05 in js language. Input & Expected Output: From: Answer You could take an offset and take a multiple floored value. If you need zeroes at the end take .toFixed(2).