Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges Calculate the Z-array

JavaScript (Node.js), 86 bytes X=>{Y=[];for(i in X)Y[i]=0,X.slice(i).map((a,b)=>a-X[b]?i='':Y[i]++);return Y.slice``} Attempt This Online! Using fancy notation, the time complexity is $...

posted 11mo ago by TheCodidacter, or rather ACodidacter‭  ·  edited 11mo ago by TheCodidacter, or rather ACodidacter‭

Answer
#4: Post edited by user avatar TheCodidacter, or rather ACodidacter‭ · 2023-06-23T17:46:58Z (11 months ago)
It -> This
  • # [JavaScript (Node.js)](https://nodejs.org/), 86 bytes
  • ```js
  • X=>{Y=[];for(i in X)Y[i]=0,X.slice(i).map((a,b)=>a-X[b]?i='':Y[i]++);return Y.slice``}
  • ```
  • [Attempt It Online!](https://ato.pxeger.com/run?1=fVLNboMwDJZ25ClyK1EDJaGd1lVhlz3DBIoilXYwRWIwAT1Ne5Jd0LQ91PY0Iz-UULTJkmPZ_vzZjt8_y-ox6z5y-nVqc-_m-yGm0WtCGd_lVe0KIEoQw4QJTgMU-00hjpkroP-cvrhuig6QRqkXswO_E3SxuJWJyyXc1Vl7qkuQaMB-_6ar_1zdt1nTNoACxjAivWCElSZGY47AauVFDBMU9CJ9AVorW1qYOwoZ9r6NyQVso-K9qKgRK7ru84nBakZiRSXzgJ12oSuHFq-KX_ASi5cM7BMOHBgS2fZIJ8fQqaFqMLSIsZkI6T2EVofbcVsSNoeYVU0gkzVfQsiZR84ChhXP9IjT2Vulr2cd_v2v4J-P5Y6jzkNdl7RodKzKpioyv6ie3Fz5IIT6mLpOv78)
  • Using fancy notation, the time complexity is
  • $$\sum^n_{i=1}i$$
  • ...or $O(n^2)$, which according to [this](https://www.freecodecamp.org/news/big-o-cheat-sheet-time-complexity-chart/) is horrible/worst haha.
  • Definitely can be optimized, but good enough for my standards 🙂
  • # [JavaScript (Node.js)](https://nodejs.org/), 86 bytes
  • ```js
  • X=>{Y=[];for(i in X)Y[i]=0,X.slice(i).map((a,b)=>a-X[b]?i='':Y[i]++);return Y.slice``}
  • ```
  • [Attempt This Online!](https://ato.pxeger.com/run?1=fVLNboMwDJZ25ClyK1EDJaGd1lVhlz3DBIoilXYwRWIwAT1Ne5Jd0LQ91PY0Iz-UULTJkmPZ_vzZjt8_y-ox6z5y-nVqc-_m-yGm0WtCGd_lVe0KIEoQw4QJTgMU-00hjpkroP-cvrhuig6QRqkXswO_E3SxuJWJyyXc1Vl7qkuQaMB-_6ar_1zdt1nTNoACxjAivWCElSZGY47AauVFDBMU9CJ9AVorW1qYOwoZ9r6NyQVso-K9qKgRK7ru84nBakZiRSXzgJ12oSuHFq-KX_ASi5cM7BMOHBgS2fZIJ8fQqaFqMLSIsZkI6T2EVofbcVsSNoeYVU0gkzVfQsiZR84ChhXP9IjT2Vulr2cd_v2v4J-P5Y6jzkNdl7RodKzKpioyv6ie3Fz5IIT6mLpOv78)
  • Using fancy notation, the time complexity is
  • $$\sum^n_{i=1}i$$
  • ...or $O(n^2)$, which according to [this](https://www.freecodecamp.org/news/big-o-cheat-sheet-time-complexity-chart/) is horrible/worst haha.
  • Definitely can be optimized, but good enough for my standards 🙂
#3: Post edited by user avatar TheCodidacter, or rather ACodidacter‭ · 2023-06-23T15:49:41Z (11 months ago)
More confidence, yeay!
  • # [JavaScript (Node.js)](https://nodejs.org/), 86 bytes
  • ```js
  • X=>{Y=[];for(i in X)Y[i]=0,X.slice(i).map((a,b)=>a-X[b]?i='':Y[i]++);return Y.slice``}
  • ```
  • [Attempt It Online!](https://ato.pxeger.com/run?1=fVLNboMwDJZ25ClyK1EDJaGd1lVhlz3DBIoilXYwRWIwAT1Ne5Jd0LQ91PY0Iz-UULTJkmPZ_vzZjt8_y-ox6z5y-nVqc-_m-yGm0WtCGd_lVe0KIEoQw4QJTgMU-00hjpkroP-cvrhuig6QRqkXswO_E3SxuJWJyyXc1Vl7qkuQaMB-_6ar_1zdt1nTNoACxjAivWCElSZGY47AauVFDBMU9CJ9AVorW1qYOwoZ9r6NyQVso-K9qKgRK7ru84nBakZiRSXzgJ12oSuHFq-KX_ASi5cM7BMOHBgS2fZIJ8fQqaFqMLSIsZkI6T2EVofbcVsSNoeYVU0gkzVfQsiZR84ChhXP9IjT2Vulr2cd_v2v4J-P5Y6jzkNdl7RodKzKpioyv6ie3Fz5IIT6mLpOv78)
  • Using fancy notation, the time complexity is
  • $$\sum^n_{i=1}i$$
  • ...or $O(n^2)$ (if I'm not wrong), which according to [this](https://www.freecodecamp.org/news/big-o-cheat-sheet-time-complexity-chart/) is horrible/worst haha.
  • Definitely can be optimized, but good enough for my standards 🙂
  • # [JavaScript (Node.js)](https://nodejs.org/), 86 bytes
  • ```js
  • X=>{Y=[];for(i in X)Y[i]=0,X.slice(i).map((a,b)=>a-X[b]?i='':Y[i]++);return Y.slice``}
  • ```
  • [Attempt It Online!](https://ato.pxeger.com/run?1=fVLNboMwDJZ25ClyK1EDJaGd1lVhlz3DBIoilXYwRWIwAT1Ne5Jd0LQ91PY0Iz-UULTJkmPZ_vzZjt8_y-ox6z5y-nVqc-_m-yGm0WtCGd_lVe0KIEoQw4QJTgMU-00hjpkroP-cvrhuig6QRqkXswO_E3SxuJWJyyXc1Vl7qkuQaMB-_6ar_1zdt1nTNoACxjAivWCElSZGY47AauVFDBMU9CJ9AVorW1qYOwoZ9r6NyQVso-K9qKgRK7ru84nBakZiRSXzgJ12oSuHFq-KX_ASi5cM7BMOHBgS2fZIJ8fQqaFqMLSIsZkI6T2EVofbcVsSNoeYVU0gkzVfQsiZR84ChhXP9IjT2Vulr2cd_v2v4J-P5Y6jzkNdl7RodKzKpioyv6ie3Fz5IIT6mLpOv78)
  • Using fancy notation, the time complexity is
  • $$\sum^n_{i=1}i$$
  • ...or $O(n^2)$, which according to [this](https://www.freecodecamp.org/news/big-o-cheat-sheet-time-complexity-chart/) is horrible/worst haha.
  • Definitely can be optimized, but good enough for my standards 🙂
#2: Post edited by user avatar TheCodidacter, or rather ACodidacter‭ · 2023-06-23T15:49:19Z (11 months ago)
Simpler O notation
  • # [JavaScript (Node.js)](https://nodejs.org/), 86 bytes
  • ```js
  • X=>{Y=[];for(i in X)Y[i]=0,X.slice(i).map((a,b)=>a-X[b]?i='':Y[i]++);return Y.slice``}
  • ```
  • [Attempt It Online!](https://ato.pxeger.com/run?1=fVLNboMwDJZ25ClyK1EDJaGd1lVhlz3DBIoilXYwRWIwAT1Ne5Jd0LQ91PY0Iz-UULTJkmPZ_vzZjt8_y-ox6z5y-nVqc-_m-yGm0WtCGd_lVe0KIEoQw4QJTgMU-00hjpkroP-cvrhuig6QRqkXswO_E3SxuJWJyyXc1Vl7qkuQaMB-_6ar_1zdt1nTNoACxjAivWCElSZGY47AauVFDBMU9CJ9AVorW1qYOwoZ9r6NyQVso-K9qKgRK7ru84nBakZiRSXzgJ12oSuHFq-KX_ASi5cM7BMOHBgS2fZIJ8fQqaFqMLSIsZkI6T2EVofbcVsSNoeYVU0gkzVfQsiZR84ChhXP9IjT2Vulr2cd_v2v4J-P5Y6jzkNdl7RodKzKpioyv6ie3Fz5IIT6mLpOv78)
  • Using fancy notation, the time complexity is
  • $$\sum^n_{i=1}i$$
  • ...or $O(\frac12n(n+1))$ (if I'm not wrong), which according to [this](https://www.freecodecamp.org/news/big-o-cheat-sheet-time-complexity-chart/) is horrible/worst haha.
  • Definitely can be optimized, but good enough for my standards 🙂
  • # [JavaScript (Node.js)](https://nodejs.org/), 86 bytes
  • ```js
  • X=>{Y=[];for(i in X)Y[i]=0,X.slice(i).map((a,b)=>a-X[b]?i='':Y[i]++);return Y.slice``}
  • ```
  • [Attempt It Online!](https://ato.pxeger.com/run?1=fVLNboMwDJZ25ClyK1EDJaGd1lVhlz3DBIoilXYwRWIwAT1Ne5Jd0LQ91PY0Iz-UULTJkmPZ_vzZjt8_y-ox6z5y-nVqc-_m-yGm0WtCGd_lVe0KIEoQw4QJTgMU-00hjpkroP-cvrhuig6QRqkXswO_E3SxuJWJyyXc1Vl7qkuQaMB-_6ar_1zdt1nTNoACxjAivWCElSZGY47AauVFDBMU9CJ9AVorW1qYOwoZ9r6NyQVso-K9qKgRK7ru84nBakZiRSXzgJ12oSuHFq-KX_ASi5cM7BMOHBgS2fZIJ8fQqaFqMLSIsZkI6T2EVofbcVsSNoeYVU0gkzVfQsiZR84ChhXP9IjT2Vulr2cd_v2v4J-P5Y6jzkNdl7RodKzKpioyv6ie3Fz5IIT6mLpOv78)
  • Using fancy notation, the time complexity is
  • $$\sum^n_{i=1}i$$
  • ...or $O(n^2)$ (if I'm not wrong), which according to [this](https://www.freecodecamp.org/news/big-o-cheat-sheet-time-complexity-chart/) is horrible/worst haha.
  • Definitely can be optimized, but good enough for my standards 🙂
#1: Initial revision by user avatar TheCodidacter, or rather ACodidacter‭ · 2023-06-23T15:16:48Z (11 months ago)
# [JavaScript (Node.js)](https://nodejs.org/), 86 bytes


```js
X=>{Y=[];for(i in X)Y[i]=0,X.slice(i).map((a,b)=>a-X[b]?i='':Y[i]++);return Y.slice``}
```

[Attempt It Online!](https://ato.pxeger.com/run?1=fVLNboMwDJZ25ClyK1EDJaGd1lVhlz3DBIoilXYwRWIwAT1Ne5Jd0LQ91PY0Iz-UULTJkmPZ_vzZjt8_y-ox6z5y-nVqc-_m-yGm0WtCGd_lVe0KIEoQw4QJTgMU-00hjpkroP-cvrhuig6QRqkXswO_E3SxuJWJyyXc1Vl7qkuQaMB-_6ar_1zdt1nTNoACxjAivWCElSZGY47AauVFDBMU9CJ9AVorW1qYOwoZ9r6NyQVso-K9qKgRK7ru84nBakZiRSXzgJ12oSuHFq-KX_ASi5cM7BMOHBgS2fZIJ8fQqaFqMLSIsZkI6T2EVofbcVsSNoeYVU0gkzVfQsiZR84ChhXP9IjT2Vulr2cd_v2v4J-P5Y6jzkNdl7RodKzKpioyv6ie3Fz5IIT6mLpOv78)

Using fancy notation, the time complexity is
$$\sum^n_{i=1}i$$

...or $O(\frac12n(n+1))$ (if I'm not wrong), which according to [this](https://www.freecodecamp.org/news/big-o-cheat-sheet-time-complexity-chart/) is horrible/worst haha.

Definitely can be optimized, but good enough for my standards 🙂