{"id":17085100,"url":"https://github.com/p1xt/algo-oct-17","last_synced_at":"2025-04-12T21:31:43.403Z","repository":{"id":88167133,"uuid":"71165330","full_name":"P1xt/algo-oct-17","owner":"P1xt","description":"JavaScript Algorithm Challenge - October 9 through 16","archived":false,"fork":false,"pushed_at":"2016-12-12T17:01:53.000Z","size":17,"stargazers_count":17,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-26T15:43:07.333Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/P1xt.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":"2016-10-17T17:48:03.000Z","updated_at":"2019-01-12T07:58:19.000Z","dependencies_parsed_at":"2023-03-16T21:15:44.513Z","dependency_job_id":null,"html_url":"https://github.com/P1xt/algo-oct-17","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/P1xt%2Falgo-oct-17","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P1xt%2Falgo-oct-17/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P1xt%2Falgo-oct-17/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P1xt%2Falgo-oct-17/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/P1xt","download_url":"https://codeload.github.com/P1xt/algo-oct-17/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248635217,"owners_count":21137191,"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":[],"created_at":"2024-10-14T13:23:15.521Z","updated_at":"2025-04-12T21:31:43.362Z","avatar_url":"https://github.com/P1xt.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#JavaScript Algorithm Challenge - October 9 through 16\n\nFrom FreeCodeCamp forums\n\nI would like to challenge everyone to solve the following algorithmic problem over the next week. Consider the problem carefully, take your time, edit your solution as many times as you want should you figure out a more efficient solution.\n\n## The challenge:\n\nCome up with the most efficient (correct) solution you can to solve the following problem.\n\n####The rules (totally unenforceable, but hey, be honest, you'll learn more):\n\n* Post your solution in spoiler tags.\n* One solution per camper, but you can edit your post (and thus your solution) as many times as you want until the challenge is over.\n* Name the function you create `mult\u003cForum Name\u003e` where `\u003cForum Name\u003e` is your name on the forums, my solution would be in a function named `multP1xt` \n* Solve the problem yourself. Don't google for an answer, don't hit stack overflow, don't read other camper's answers.\n* To the extent that it's possible, limit yourself to one post in this thread (so it'll be easier for me to round up everybody's answers at the end.\n* Please avoid discussion after you've solved the problem until the challenge is over, so you don't spoiler others and mess up their chances to solve the problem on their own.\n\n##The Problem:\n\n\u003e If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.\n\n\u003e If we list all the natural numbers below 20 that are multiples of 3 or 5, we get 3, 5, 6, 9, 10, 12, 15, 18. The sum of these multiples is 78.\n\n\u003e Write a JavaScript function that will find the sum of all multiples of 3 or 5 that are below a number N, where N is an input parameter to the function.\n\n##Helpful Notes:\n\nAny camper who wants can join in this, if you're not up to the JavaScript section of FCC yet, hit [codecademy (javascript lessons)](https://www.codecademy.com/learn/javascript)  and then code your solution on [repl.it](https://repl.it/languages/javascript). Once you've got it working, copy the code into a post here (inside spoiler tags, of course). (I just double checked and the lessons I linked from codecademy teach everything you'd need to know to code a working solution to this problem). \n\nYou can use the [benchmarkjs](https://benchmarkjs.com/) npm module and Node.js to benchmark your various solutions to ensure that you submit your most efficient attempt. (I'll be using benchmarkjs with Node.js 6.5 to determine efficiency at the end of the contest).\n\nI listed two test cases above. Here are a few more so you can ensure your solution is both correct AND efficient: \n```\nInput: 10    Output: 23\nInput: 20    Output: 78\nInput: 100   Output: 2318\nInput: 10000 Output: 23331668\nInput: 45678 Output: 486804150\n```\nTake note that numbers which are multiples of both 3 and 5 (like 15) are only included in the sum once.\n\nYou create spoiler tags by enclosing your spoiler text in between `[details=\"Spoiler\"]Text you want to hide[/details]`\n\nHere's exactly how to put a code snippet inside a Spoiler tag. You can copy it directly (be sure to get the blank line at  the top) and paste it into your post, then replace the `function multX` part with your own function.\n\n    \n    [details=Spoiler]\n\n    ```javascript\n\n    function multX(times) {\n      \n    }\n\n    ```\n\n    [/details]\n\nI will be testing and benchmarking all solutions using Node.js 6.5 (so you can feel free to use any ES6 that will run in 6.5, which is most of it).\n\n@JacksonBates Wrote up a handy tutorial on how to use Mocha and Chai to write a handy test runner to double check that your function produces the correct values here: http://forum.freecodecamp.com/t/testing-your-own-code-using-mocha-and-chai-simple-example/44149 \n\n##When the challenge ends:\n\nHere's a handy countdown timer so you know how long before the challenge ends:\nhttps://countingdownto.com/countdown/multiples-of-3-and-5-countdown-clock\n\nThe morning after the challenge ends, I'll first test everyone's answer to ensure it's correct, then benchmark all of the correct solutions. \n\n##The Reward?\n\nAside from the pure fun of practicing creating efficient algorithms, I don't have a lot to offer. Though I will post the names of everyone who solved the problem, with a special list of those who solved it the most efficiently as an edit to this post.\n\n##The Results\n###Correct solutions\nThe following campers put forth solutions that correctly solved the challenge. \n@JacksonBates,\n@kevcomedia,\n@Salasy,\n@nickolaos77,\n@Michealhall,\n@Darklake,\n@BenGitter,\n@jv88899,\n@simmco,\n@JohnL3,\n@Foresterr,\n@Frustrated_Coder,\n@computerluca,\n@brew95,\n@thanhacun,\n@Velenir,\n@slocodemonkey,\n@IdyR17,\n@Omegga,\n@G-Squirrel,\n@imtoobose,\n@vector2016,\n@IsaacAbrahamson,\n@Gouldie,\n@Tattomoosa,\n@HyperSprite,\n@tsaulon,\n@Jasil1414,\n@BLK1010,\n@pkmn9060,\n@nawazishali,\n@Np463,\n@YankeeDK,\n@MistaTwist,\n@a402539,\n@TsvetkovT,\n@ShanthiKarunakaran,\n@ZackWard,\n@joelpeyton,\n@Lee182,\n@Anourian,\n@IronPike,\n@ayiemba,\n@SabryRagab,\n@mpontus,\n@silgarth,\n@analistamarcio,\n@bhattmayur26,\n@Davidrfreeman,\n@Ephopper,\n@NostalgieCamarade,\n@paulo101977,\n@hit1st,\n@79man,\n\n\nNote: In some cases, I modified the function name submitted in order to match `mult\u003ccampername\u003e` for ease of testing. In one case, I copied the function off repl.it as it was linked from repl.it instead of included in a spoiler tag and in one case I added a return statement to an otherwise correct solution. This might seem \"unfair\", however, in the spirit of including everyone, I didn't want to exclude correct solutions for \"picky\" reasons, especially since the brief was rather lengthy and not all our campers speak English natively. \n\nIn one case I removed a console.log() purely to remove that output from the benchmark results.\n\n\n\n###The most efficient solutions were the following\nmultsilgarth x 6,753,148 ops/sec ±0.54% (89 runs sampled)  \n\nmultForesterr x 6,675,344 ops/sec ±1.00% (86 runs sampled)  \n\nmultYankeeDK x 6,638,467 ops/sec ±1.93% (85 runs sampled)  \n\nmultIronPike x 5,820,219 ops/sec ±1.18% (85 runs sampled) \n\nmultnickolaos77 x 5,632,879 ops/sec ±1.93% (84 runs sampled)  \n\nmulta402539 x 5,311,919 ops/sec ±0.98% (84 runs sampled)  \n\n\n##Using this repository\n\nNode version 6.5\n\n`npm install`\n\n`node benchmark.js` to run benchmarks\n\n`mocha test.js` to run tests\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp1xt%2Falgo-oct-17","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fp1xt%2Falgo-oct-17","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp1xt%2Falgo-oct-17/lists"}