{"id":19716720,"url":"https://github.com/obadakhalili/dynamo","last_synced_at":"2026-05-13T18:10:42.314Z","repository":{"id":118169881,"uuid":"268280587","full_name":"obadakhalili/Dynamo","owner":"obadakhalili","description":"💥 C++ dynamic array library that has an API similar to the JavaScript array API","archived":false,"fork":false,"pushed_at":"2020-07-23T20:34:43.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-10T15:25:03.161Z","etag":null,"topics":["array","cpp","js"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/obadakhalili.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-31T12:58:36.000Z","updated_at":"2020-09-17T21:55:04.000Z","dependencies_parsed_at":"2023-03-29T18:21:05.321Z","dependency_job_id":null,"html_url":"https://github.com/obadakhalili/Dynamo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obadakhalili%2FDynamo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obadakhalili%2FDynamo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obadakhalili%2FDynamo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obadakhalili%2FDynamo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/obadakhalili","download_url":"https://codeload.github.com/obadakhalili/Dynamo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241037177,"owners_count":19898294,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","cpp","js"],"created_at":"2024-11-11T22:43:11.642Z","updated_at":"2026-05-13T18:10:37.277Z","avatar_url":"https://github.com/obadakhalili.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dynamo\n\nThis library was designed to be similar to the modern high-level scripting languages array API, but specifically similar to the JavaScript array API.\n\n## Code Integration\nIf you want to link this library statically into your code, You can watch [this](https://www.youtube.com/watch?v=Wt4dxDNmDA8) video from TheCherno to knowhow.\n\n## Usage\n### Declaration\n```\tc++\ndynamo::Array\u003c[type]\u003e name([constructor option]);\n```\nThe constructor option could be one of three things:\n1. Array Capacity (type: number, default value: 10).\n2. Copy Constructor (copying other array object contents).\n3. Array Pointer (size should be specified).\n#### Examples:\n```c++\ndynamo::Array\u003cint\u003e arr1; // default capacity to 10\ndynamo::Array\u003cint\u003e arr2(7); // capacity\ndynamo::Array\u003cint\u003e arr3(arr2); // copy constructor\n\nint numbers[3] = { 1, 2, 3 };\ndynamo::Array\u003cint\u003e arr4(numbers, 3); // array pointer\n```\n### Data Access\nYou can access data in two ways. The array subscrip operators ``[]`` or the ``.peak()`` method.\n#### Examples:\n```c++\nint numbers[3] = { 1, 2, 3 };\ndynamo::Array\u003cint\u003e arr(numbers, 3);\n\narr[0]; // 1\narr.peak(1); // 2\n```\n**Note:  the array subscripting operators can't be used to manipulate data. Only used to access it.**\n### Data Manipulation\nAll available member functions for data manipulation are:\n1. ``.pop()`` Removes the array last element.\n2. ``.shift()`` Removes the array first element.\n3. ``.splice(startingIndex, numberOfItemsToDelete, { elements to add })`` Similar to the JavaScript array ``.splice()`` method. It takes a starting index, removes elements as much as you want starting from the specified starting point, then starts to add elements from there.\n4. ``.push(item)`` Adds an element at the end of the array.\n5. ``.unshift(item)`` Adds an element at the start of the array.\n6. ``.sort(order, start, end)``  Sorts an array in both ascending and descending order.\n\t``.sort()`` by default sorts ascendingly, but if you want to change the order, you can use positive and negative integers to specify that. For example, to sort descendingly you can write ``.sort(-1)``.\n7. ``.copy()`` Takes other array object and copies its content.\n8. ``.concat()`` Takes both an array object and ``initializer_list `` and concatenate its content to an array. \n#### Examples:\n```c++\ndynamo::Array\u003cint\u003e arr1, arr2;\n\narr1.push(-1).push(2).push(7).push(5).unshift(-3); // appends -1, 2, 7, and 5 to the end of the array, and adds -3 to the start of the array\n\narr1.sort(); // sorts the specified array\n\narr1.pop().shift(); // removes the first and last array element\n\narr1.concat({ 10, 20, 30, 40 }); // concatenate { 10, 20, 30, 40 } to the end of the array\n\narr1.splice(1, 2, { 100, 5 }); // starting at index 1. It removes the first 2 elements and replaces them with 100 and 5\n\narr2.copy(arr1); // copies arr1 content to arr2\n\nfor (int i = 0; i \u003c arr2.length(); i++) {\n  std::cout \u003c\u003c arr2[i] \u003c\u003c std::endl; // -1, 100, 5, 10, 20, 30, 40\n}\n```\n**Note: all the mentioned methods can be chained together.**\n## Informative Methods\n1. ``.length()`` Returns the arrays size.\n2. ``.includes(item)`` Returns true if the passed item is inside the array, and returns false otherwise.\n3. ``indexOf(item)`` Returns the index of the specified element and returns -1 otherwise.\n4. ``lastIndexOf(item)`` Returns the index of the specified element starting from the last element, and returns -1 otherwise.\n5. ``.begin()`` Returns a pointer to the array first element.\n6. ``.end()`` Returns a pointer to the array last element.\n\n### Higher-Order Array Methods\nDynamo has ``.forEach()``, ``.map()``, ``.filter()``, ``.reduce()``,  ``.find()``, and ``.findIndex()`` that works exactly the same way JavaScruipt higher-order methods works with a few exceptions to the ``.reduce()`` method.\n**If you are not aware of the JavaScript higher-order array methods and how they work, Check out this\n[article](https://blog.bitsrc.io/understanding-higher-order-functions-in-javascript-75461803bad). You are missing a lot!.**\nYou will find a small explanation for each method and what it does.\n#### Examples:\n```c++\n#include \"Dynamo.cpp\"\n\n#include \u003ciostream\u003e\n\nint timesTwo(const int number, const int index) {\n  return number * 2;\n}\n\nint main() {\n  dynamo::Array\u003cint\u003e numbers;\n\n  numbers.concat({ 1, 2, 10, 5, 7 });\n\n  /* Iterate over each item and execute the given callback\n  function for each, Note that I'm using the lambda\n  function notation, however, you can use a normal function. */\n  numbers.forEach([](const int number, const int index) {\n    if (number % 2 == 0) {\n      printf(\"Index: %d, Item: %d\\n\", index, number);\n    }\n  });\n  /* Prints:\n  Index: 1, Item: 2\n  Index: 2, Item: 10\n  */\n\n  /* Map over each item and execute the given callback\n  function for each, and place each returned item in its\n  position in the new array.\n  */\n  dynamo::Array\u003cint\u003e mappedNumbers = numbers.map(timesTwo); // mappedNumbers =\u003e { 2, 4, 20, 10, 14 }.\n\n  dynamo::Array\u003cstd::string\u003e strings;\n\n  strings.concat({ \"a\", \"ab\", \"abc\", \"abcd\", \"abcde\" });\n\n  /* Iterate over each item and execute the given callback\n  function for each, and only returns the item to the new array\n  if the item, size is greater than 2.\n  */\n  dynamo::Array\u003cstd::string\u003e filteredStrings = strings.filter([](std::string string, const int index) {\n    return string.size() \u003e 2;\n  }); // filteredNames =\u003e { \"abc\", \"abcd\", \"abcde\" }.\n\n  /* Summarize (reduce) the given array into one value\n  And prints its output to the console. Note that the accumulator initial value starts at \"a, ab\".\n  */\n  std::cout \u003c\u003c filteredStrings.reduce([](std::string acc, std::string string, const int index) {\n    return acc + \", \" + string;\n  }, \"a, ab\"); // Prints: a, ab, abc, abcd, abcde.\n\n\n  // Returns the first element that satisfies the given condition.\n  numbers.find([](const int number, const int index) {\n    return number \u003e 5;\n  }); // Returns 10.\n\n  // Returns the index of the first element that satisfies the given condition.\n  numbers.findIndex([](const int number, const int index) {\n    return number \u003e 5;\n  }); // Returns 2.\n\n  return 0;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobadakhalili%2Fdynamo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fobadakhalili%2Fdynamo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobadakhalili%2Fdynamo/lists"}