Skip to content

Instantly share code, notes, and snippets.

@vasilionjea
Created June 12, 2024 21:25
Show Gist options
  • Save vasilionjea/ebe7092efccee3119bb878009dc19b7f to your computer and use it in GitHub Desktop.
Save vasilionjea/ebe7092efccee3119bb878009dc19b7f to your computer and use it in GitHub Desktop.
function test() {
const nums = [1, 2, 3];
for (let i = 0; i < 60; i++) {
const first = nums[0];
const mid = nums[1];
nums.splice(2, 1); // delete last number
const newMid = (first + mid) / 2;
nums.splice(1, 0, newMid);
}
}
test();
// (0): [1, 2, 3]
// (1): [1, 1.5, 2]
// (2): [1, 1.25, 1.5]
// (3): [1, 1.125, 1.25]
// (4): [1, 1.0625, 1.125]
// (5): [1, 1.03125, 1.0625]
// (6): [1, 1.015625, 1.03125]
// (7): [1, 1.0078125, 1.015625]
// (8): [1, 1.00390625, 1.0078125]
// (9): [1, 1.001953125, 1.00390625]
// (10): [1, 1.0009765625, 1.001953125]
// (11): [1, 1.00048828125, 1.0009765625]
// (12): [1, 1.000244140625, 1.00048828125]
// (13): [1, 1.0001220703125, 1.000244140625]
// (14): [1, 1.00006103515625, 1.0001220703125]
// (15): [1, 1.000030517578125, 1.00006103515625]
// (16): [1, 1.0000152587890625, 1.000030517578125]
// (17): [1, 1.0000076293945312, 1.0000152587890625]
// (18): [1, 1.0000038146972656, 1.0000076293945312]
// (19): [1, 1.0000019073486328, 1.0000038146972656]
// (20): [1, 1.0000009536743164, 1.0000019073486328]
// (21): [1, 1.0000004768371582, 1.0000009536743164]
// (22): [1, 1.000000238418579, 1.0000004768371582]
// (23): [1, 1.0000001192092896, 1.000000238418579]
// (24): [1, 1.0000000596046448, 1.0000001192092896]
// (25): [1, 1.0000000298023224, 1.0000000596046448]
// (26): [1, 1.0000000149011612, 1.0000000298023224]
// (27): [1, 1.0000000074505806, 1.0000000149011612]
// (28): [1, 1.0000000037252903, 1.0000000074505806]
// (29): [1, 1.0000000018626451, 1.0000000037252903]
// (30): [1, 1.0000000009313226, 1.0000000018626451]
// (31): [1, 1.0000000004656613, 1.0000000009313226]
// (32): [1, 1.0000000002328306, 1.0000000004656613]
// (33): [1, 1.0000000001164153, 1.0000000002328306]
// (34): [1, 1.0000000000582077, 1.0000000001164153]
// (35): [1, 1.0000000000291038, 1.0000000000582077]
// (36): [1, 1.000000000014552, 1.0000000000291038]
// (37): [1, 1.000000000007276, 1.000000000014552]
// (38): [1, 1.000000000003638, 1.000000000007276]
// (39): [1, 1.000000000001819, 1.000000000003638]
// (40): [1, 1.0000000000009095, 1.000000000001819]
// (41): [1, 1.0000000000004547, 1.0000000000009095]
// (42): [1, 1.0000000000002274, 1.0000000000004547]
// (43): [1, 1.0000000000001137, 1.0000000000002274]
// (44): [1, 1.0000000000000568, 1.0000000000001137]
// (45): [1, 1.0000000000000284, 1.0000000000000568]
// (46): [1, 1.0000000000000142, 1.0000000000000284]
// (47): [1, 1.000000000000007, 1.0000000000000142]
// (48): [1, 1.0000000000000036, 1.000000000000007]
// (49): [1, 1.0000000000000018, 1.0000000000000036]
// (50): [1, 1.0000000000000009, 1.0000000000000018]
// (51): [1, 1.0000000000000004, 1.0000000000000009]
// (52): [1, 1.0000000000000002, 1.0000000000000004]
// (53): [1, 1, 1.0000000000000002]
// (54): [1, 1, 1]
// (55): [1, 1, 1]
// (56): [1, 1, 1]
// (57): [1, 1, 1]
// (58): [1, 1, 1]
// (59): [1, 1, 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment