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

75%
+4 −0
Challenges Is it a near-anagram?

JavaScript (Node.js), 150 71 bytes f=(a,b)=>a[b.length]?f(b,a):b.filter(x=>a[y=a.indexOf(x)]=!~y).length-1 Try it online!

posted 4y ago by Hakerh400‭  ·  edited 4y ago by Hakerh400‭

Answer
#8: Post edited by user avatar Hakerh400‭ · 2021-02-17T09:11:41Z (almost 4 years ago)
  • # [JavaScript (Node.js)], <del>150</del> 69 bytes
  • <!-- language-all: lang-javascript -->
  • (a,b)=>a[b.length]?f(b,a):b.filter(x=>a[y=a.indexOf(x)]=!~y).length-1
  • [Try it online!][TIO-kl97oflw]
  • [JavaScript (Node.js)]: https://nodejs.org
  • [TIO-kl97oflw]: https://tio.run/##Tc5Ba8IwFAfwez/F89QEanDXjTiSpoeBWBE9lRxSTVylNpJmo8LYV@@abG67PX7v/Xn/s3pX/cE1Vz/v7FGPho5IZTWmS1XVpNXdyb/KZ4PqTOHHmpim9dqhIaxvVJGmO@qhNGjAks4@b/gnMX8YD7brPXjd@x4oVAlAlTJR8iLNIGW8FEUqs6i7/WYVdbdfvWzuynguogomeH5XzraTAYRh/Q/XQcOwLX6Z5fE0fIt5@ZQkxjr01wys@W6Ip0Bg22rS2hOaGUQICStyUVekgC6hmoS/GaMdMc5ekMISY/iABR6/AA "JavaScript (Node.js) – Try It Online"
  • # [JavaScript (Node.js)], <del>150</del> 71 bytes
  • <!-- language-all: lang-javascript -->
  • f=(a,b)=>a[b.length]?f(b,a):b.filter(x=>a[y=a.indexOf(x)]=!~y).length-1
  • [Try it online!][TIO-kl97oflw]
  • [JavaScript (Node.js)]: https://nodejs.org
  • [TIO-kl97oflw]: https://tio.run/##Tc5Ba8IwFAfwez/F89QEanDXjTiSpoeBWBE9lRxSTVylNpJmo8LYV@@abG67PX7v/Xn/s3pX/cE1Vz/v7FGPo6FIZTWmS1XVpNXdyb/KZ4PqTOHHmpim9dqhIaxvVJGmO@qhNGjAks4@b/gnMX8YD7brPXjd@x4oVAlAlTJR8iLNIGW8FEUqs6i7/WYVdbdfvWzuynguogomeH5XzraTAYRh/Q/XQcOwLX6Z5fE0fIt5@ZQkxjr01wys@W6Ip0Bg22rS2hOaGUQICStyUVekgC6hmoS/GaMdMc5ekMISY/iABR6/AA "JavaScript (Node.js) – Try It Online"
#7: Post edited by user avatar Hakerh400‭ · 2021-02-17T09:09:53Z (almost 4 years ago)
  • # [JavaScript (Node.js)], <del>150</del> 112 bytes
  • <!-- language-all: lang-javascript -->
  • (a,b,e=(x,y,[a,...b]=x,[c,...d]=y)=>a?a^c?b==d+''|x==d+''|y==b+'':c?e(b,d):b!='':c&&d=='')=>e(a.sort(),b.sort())
  • [Try it online!][TIO-kl962rhv]
  • [JavaScript (Node.js)]: https://nodejs.org
  • [TIO-kl962rhv]: https://tio.run/##TdBRa8IwEAfwdz/F9cUmLAt7dpwlafswEBXRp9JB0iZjQ4203WjB794lnW57un9@yXFHPtSXaqvm/dI9nl1tRosjUUwzg6RnAysU45zrEntWVCHWJQ4UlypRr1WiEeuHOL72tzogal8XVWKIZjVd6AjDcT6v0QffZ4jirWs6Qpm@BTpW7tx20Jm2awGhmAEUscg2Mo8ZxEJusjwu2aT7w3Y16f6wetneVcg0mzQTmUzvKsXOG0AI63@4DhrCLv9lkU5Pw7Spv3yezaxryN9m4OzPhtQ3BHZHw4/ujUSRJf5fwh0/qQtRgEsovMhPa03DbeNORNGSUrjCEx2/AQ "JavaScript (Node.js) – Try It Online"
  • # [JavaScript (Node.js)], <del>150</del> 69 bytes
  • <!-- language-all: lang-javascript -->
  • (a,b)=>a[b.length]?f(b,a):b.filter(x=>a[y=a.indexOf(x)]=!~y).length-1
  • [Try it online!][TIO-kl97oflw]
  • [JavaScript (Node.js)]: https://nodejs.org
  • [TIO-kl97oflw]: https://tio.run/##Tc5Ba8IwFAfwez/F89QEanDXjTiSpoeBWBE9lRxSTVylNpJmo8LYV@@abG67PX7v/Xn/s3pX/cE1Vz/v7FGPho5IZTWmS1XVpNXdyb/KZ4PqTOHHmpim9dqhIaxvVJGmO@qhNGjAks4@b/gnMX8YD7brPXjd@x4oVAlAlTJR8iLNIGW8FEUqs6i7/WYVdbdfvWzuynguogomeH5XzraTAYRh/Q/XQcOwLX6Z5fE0fIt5@ZQkxjr01wys@W6Ip0Bg22rS2hOaGUQICStyUVekgC6hmoS/GaMdMc5ekMISY/iABR6/AA "JavaScript (Node.js) – Try It Online"
#6: Post edited by user avatar Hakerh400‭ · 2021-02-17T08:25:04Z (almost 4 years ago)
  • # [JavaScript (Node.js)], <del>150</del> 97 bytes
  • <!-- language-all: lang-javascript -->
  • (a,b,e=(x,y,[a,...b]=x,[c,...d]=y)=>a?a-c?b==d+''
  • |x==d+''|y==b+'':e(b,d):c)=>e(a.sort(),b.sort())
  • [Try it online!][TIO-kl949ukz]
  • [JavaScript (Node.js)]: https://nodejs.org
  • [TIO-kl949ukz]: https://tio.run/##TdBRa8IwEAfw936K8ykJi2HPjlOStg8DURF9Kn1I0mRsqJG2Gy343bum021P9@eXO3Lch/7Sja3fr@38Eio3eByo5oY7pB3veaG5EMKU2PHCxliV2DNc6pWe25VBrJ4IuXX32iOasS4cNbxiCzs2OqpFE@qWMm7ugQ02XJoWWte0DSAUCUBBZLZVOeFApNpmOSn5pIfjbj3p4bh@3T1UqjSbNJOZSh@q5H40gBg2/3ATNYZ9/ssynVrjb9N8@ZIkPtT0bzMI/mdDNg5EDicnTuGNzmaejoeIb@Ksr1QDLkF9eu9q4etwppoxBjd4ZsM3 "JavaScript (Node.js) – Try It Online"
  • # [JavaScript (Node.js)], <del>150</del> 112 bytes
  • <!-- language-all: lang-javascript -->
  • (a,b,e=(x,y,[a,...b]=x,[c,...d]=y)=>a?a^c?b==d+''|x==d+''|y==b+'':c?e(b,d):b!='':c&&d=='')=>e(a.sort(),b.sort())
  • [Try it online!][TIO-kl962rhv]
  • [JavaScript (Node.js)]: https://nodejs.org
  • [TIO-kl962rhv]: https://tio.run/##TdBRa8IwEAfwdz/F9cUmLAt7dpwlafswEBXRp9JB0iZjQ4203WjB794lnW57un9@yXFHPtSXaqvm/dI9nl1tRosjUUwzg6RnAysU45zrEntWVCHWJQ4UlypRr1WiEeuHOL72tzogal8XVWKIZjVd6AjDcT6v0QffZ4jirWs6Qpm@BTpW7tx20Jm2awGhmAEUscg2Mo8ZxEJusjwu2aT7w3Y16f6wetneVcg0mzQTmUzvKsXOG0AI63@4DhrCLv9lkU5Pw7Spv3yezaxryN9m4OzPhtQ3BHZHw4/ujUSRJf5fwh0/qQtRgEsovMhPa03DbeNORNGSUrjCEx2/AQ "JavaScript (Node.js) – Try It Online"
#5: Post edited by user avatar Hakerh400‭ · 2021-02-17T07:44:59Z (almost 4 years ago)
  • # [JavaScript (Node.js)], <del>150</del> 97 bytes
  • <!-- language-all: lang-javascript -->
  • (a,b,e=(x,y,[a,...b]=x,[c,...d]=y)=>a?a-c?b==d+''
  • |x==d+''|y==b+'':e(b,d):c)=>e(a.sort(),b.sort())
  • [Try it online!][TIO-kl949ukz]
  • [JavaScript (Node.js)]: https://nodejs.org
  • [TIO-kl949ukz]: https://tio.run/##TdBRa8IwEAfw936Ke0vCYtiz45Sk7YMgKqJPpQ9JmoyJGmm70YLfvWs63fZ0f365I8ed9JdubP1xa2fXULnB40A1N9wh7XjPC82FEKbEjhc2xqrEnuFCL/XMLg1i9ULIvXvUHtGMde6o4RWb27HRUS2aULeUcfMIbLDh2rTQuqZtAKFIAAois63KCQci1TbLScknPRx360kPx/Vq91Sp0mzSTGYqfaqS@9EAYtj8w03UGPb5L8t0ao2/TfPlW5L4UNO/zSD4nw3ZOBA5nJ04h3fq6XiG@CIu@kY14ALUp/euFr4OF6oZY3CHVzZ8Aw "JavaScript (Node.js) – Try It Online"
  • # [JavaScript (Node.js)], <del>150</del> 97 bytes
  • <!-- language-all: lang-javascript -->
  • (a,b,e=(x,y,[a,...b]=x,[c,...d]=y)=>a?a-c?b==d+''
  • |x==d+''|y==b+'':e(b,d):c)=>e(a.sort(),b.sort())
  • [Try it online!][TIO-kl949ukz]
  • [JavaScript (Node.js)]: https://nodejs.org
  • [TIO-kl949ukz]: https://tio.run/##TdBRa8IwEAfw936K8ykJi2HPjlOStg8DURF9Kn1I0mRsqJG2Gy343bum021P9@eXO3Lch/7Sja3fr@38Eio3eByo5oY7pB3veaG5EMKU2PHCxliV2DNc6pWe25VBrJ4IuXX32iOasS4cNbxiCzs2OqpFE@qWMm7ugQ02XJoWWte0DSAUCUBBZLZVOeFApNpmOSn5pIfjbj3p4bh@3T1UqjSbNJOZSh@q5H40gBg2/3ATNYZ9/ssynVrjb9N8@ZIkPtT0bzMI/mdDNg5EDicnTuGNzmaejoeIb@Ksr1QDLkF9eu9q4etwppoxBjd4ZsM3 "JavaScript (Node.js) – Try It Online"
#4: Post edited by user avatar Hakerh400‭ · 2021-02-17T07:40:09Z (almost 4 years ago)
  • # [JavaScript (Node.js)], <del>150</del> 113 bytes
  • <!-- language-all: lang-javascript -->
  • (a,b,c=a=>a.sort((a,b)=>a-b),e=(x,y,[a,...b]=x,[c,...d]=y
  • )=>a?a-c?b==d+''|x==d+''|y==b+'':e(b,d):c)=>e(c(a),c(b))
  • [Try it online!][TIO-kl949ukz]
  • [JavaScript (Node.js)]: https://nodejs.org
  • [TIO-kl949ukz]: https://tio.run/##Tc/BasMwDADQe75Ct9jMMTt3qMVOchiUtpT2FHKwHbtstHVJspFA/z2zs3XbSfKzhKR39ak6077d@uzqGzs5nIhimhlUuFS8821PItDwyjRlFsnARlYpxjnXNQ6sMjFtahxjzUplZqURm6c0vQ8/cUTUIS4s0ayhCxMKLTFEUWaIpnQy/tr10Nuu7wChSgCqVBRbWaYMUiG3RZnWbNbDcbee9XBcv@4eKmRezFqIQuYPlWIfDCAmm3@4iRqTffnLIp9L47S5v35JEudb8rcZePe9IQ0Nkf3Z8rM/EUfC@fGHX9SNKMAlyA/nbMtd6y/hSErhDs90@gI "JavaScript (Node.js) – Try It Online"
  • # [JavaScript (Node.js)], <del>150</del> 97 bytes
  • <!-- language-all: lang-javascript -->
  • (a,b,e=(x,y,[a,...b]=x,[c,...d]=y)=>a?a-c?b==d+''
  • |x==d+''|y==b+'':e(b,d):c)=>e(a.sort(),b.sort())
  • [Try it online!][TIO-kl949ukz]
  • [JavaScript (Node.js)]: https://nodejs.org
  • [TIO-kl949ukz]: https://tio.run/##TdBRa8IwEAfw936Ke0vCYtiz45Sk7YMgKqJPpQ9JmoyJGmm70YLfvWs63fZ0f365I8ed9JdubP1xa2fXULnB40A1N9wh7XjPC82FEKbEjhc2xqrEnuFCL/XMLg1i9ULIvXvUHtGMde6o4RWb27HRUS2aULeUcfMIbLDh2rTQuqZtAKFIAAois63KCQci1TbLScknPRx360kPx/Vq91Sp0mzSTGYqfaqS@9EAYtj8w03UGPb5L8t0ao2/TfPlW5L4UNO/zSD4nw3ZOBA5nJ04h3fq6XiG@CIu@kY14ALUp/euFr4OF6oZY3CHVzZ8Aw "JavaScript (Node.js) – Try It Online"
#3: Post edited by user avatar Hakerh400‭ · 2021-02-17T07:35:53Z (almost 4 years ago)
  • # JavaScript, 150 bytes
  • <!-- language-all: lang-javascript -->
  • (a,b,c=([...a])=>a.map(a=>c.set(a,-~c.get(a)),c=new Map)&&c)=>[...c(a+b,b=c
  • (b))].map(([x,y,z=y-(b.get(x)<<1)])=>c|=z-1?z+1?z:e++:d++,c=d=e=0)&&!c&&d|e
  • [Try it online!][TIO-kl0e73a9]
  • [TIO-kl0e73a9]: https://tio.run/##TZDNasMwEITvfortxZaQLJJrGqXIP4dCmoSQnIwPsiyHltQ2sWkTY/rqrqSStgfB8O3M7KI3@SE7dXlt@7BuSj1VfEKSFlRxlDHGZI75SrJ32SLJV4p1ujfj8Euxk1UYG2OtP@FFttj3lTHblEKSFLTgChUY5y6Nsiu90YHfQlS47BUvl3Ns69XIh3D@NBDzFpqQRUmIqS255jNT@qB8vxz1pJq666HXXd8Bh8wDyAKRbKM0oBCIaJukQU4dPRx3a0cPx/Xz7k5FFCeOJiKJ4juNxN4wACs2/@DGUiv26S8WsbPabS6fP3pe1VzQ32XQVD8XYhOwuDlrdm5OqELmW@wEwwgzPH0D "JavaScript (Node.js) – Try It Online"
  • # [JavaScript (Node.js)], <del>150</del> 113 bytes
  • <!-- language-all: lang-javascript -->
  • (a,b,c=a=>a.sort((a,b)=>a-b),e=(x,y,[a,...b]=x,[c,...d]=y
  • )=>a?a-c?b==d+''|x==d+''|y==b+'':e(b,d):c)=>e(c(a),c(b))
  • [Try it online!][TIO-kl949ukz]
  • [JavaScript (Node.js)]: https://nodejs.org
  • [TIO-kl949ukz]: https://tio.run/##Tc/BasMwDADQe75Ct9jMMTt3qMVOchiUtpT2FHKwHbtstHVJspFA/z2zs3XbSfKzhKR39ak6077d@uzqGzs5nIhimhlUuFS8821PItDwyjRlFsnARlYpxjnXNQ6sMjFtahxjzUplZqURm6c0vQ8/cUTUIS4s0ayhCxMKLTFEUWaIpnQy/tr10Nuu7wChSgCqVBRbWaYMUiG3RZnWbNbDcbee9XBcv@4eKmRezFqIQuYPlWIfDCAmm3@4iRqTffnLIp9L47S5v35JEudb8rcZePe9IQ0Nkf3Z8rM/EUfC@fGHX9SNKMAlyA/nbMtd6y/hSErhDs90@gI "JavaScript (Node.js) – Try It Online"
#2: Post edited by user avatar Hakerh400‭ · 2021-02-17T06:07:57Z (almost 4 years ago)
  • # JavaScript, 150 bytes
  • <!-- language-all: lang-javascript -->
  • (a,b,c=([...a])=>a.map(a=>c.set(a,-~c.get(a)),c=new Map)&&c)=>[...c(a+b,b=c
  • (b))].map(([x,y,z=y-(b.get(x)<<1)])=>c|=z-1?z+1?z:e++:d++,c=d=e=0)&&!c&&d|e
  • [Try it online!][TIO-kl0e73a9]
  • [TIO-kl0e73a9]: https://tio.run/##TZBBi8IwEIXv/RWzlzYhadCra1xa28OCqyJ6Kj2kaSor2hRbdrWU/evdJCK7h4HHN/MejzmJL9HK62fThbUu1VjxEQlaUMlRxhgTOeYLwS6iQYIvJGtVZ9bhj2RHqzA2h7X6hg/RYN@X5ti6JBKkoAWXqMA4d26U3eid9vweosJ5b3g@n2IbLwfeh9O3npiZKUJmJSEmtuSKT0zoi/T9clCj1HXbQafargUOmQeQBVGyidOAQhDFmyQNcuro/rBdObo/rN63TxrFy8TRJEri5ZPG0c4wACvW/@DaUit2qcP5q@dV@or@WoCuHm2w8Visz4qd9RFVyLzAbjAMMMHjLw "JavaScript (Node.js) – Try It Online"
  • # JavaScript, 150 bytes
  • <!-- language-all: lang-javascript -->
  • (a,b,c=([...a])=>a.map(a=>c.set(a,-~c.get(a)),c=new Map)&&c)=>[...c(a+b,b=c
  • (b))].map(([x,y,z=y-(b.get(x)<<1)])=>c|=z-1?z+1?z:e++:d++,c=d=e=0)&&!c&&d|e
  • [Try it online!][TIO-kl0e73a9]
  • [TIO-kl0e73a9]: https://tio.run/##TZDNasMwEITvfortxZaQLJJrGqXIP4dCmoSQnIwPsiyHltQ2sWkTY/rqrqSStgfB8O3M7KI3@SE7dXlt@7BuSj1VfEKSFlRxlDHGZI75SrJ32SLJV4p1ujfj8Euxk1UYG2OtP@FFttj3lTHblEKSFLTgChUY5y6Nsiu90YHfQlS47BUvl3Ns69XIh3D@NBDzFpqQRUmIqS255jNT@qB8vxz1pJq666HXXd8Bh8wDyAKRbKM0oBCIaJukQU4dPRx3a0cPx/Xz7k5FFCeOJiKJ4juNxN4wACs2/@DGUiv26S8WsbPabS6fP3pe1VzQ32XQVD8XYhOwuDlrdm5OqELmW@wEwwgzPH0D "JavaScript (Node.js) – Try It Online"
#1: Initial revision by user avatar Hakerh400‭ · 2021-02-17T05:01:42Z (almost 4 years ago)
# JavaScript, 150 bytes

<!-- language-all: lang-javascript -->

    (a,b,c=([...a])=>a.map(a=>c.set(a,-~c.get(a)),c=new Map)&&c)=>[...c(a+b,b=c
    (b))].map(([x,y,z=y-(b.get(x)<<1)])=>c|=z-1?z+1?z:e++:d++,c=d=e=0)&&!c&&d|e

[Try it online!][TIO-kl0e73a9]

[TIO-kl0e73a9]: https://tio.run/##TZBBi8IwEIXv/RWzlzYhadCra1xa28OCqyJ6Kj2kaSor2hRbdrWU/evdJCK7h4HHN/MejzmJL9HK62fThbUu1VjxEQlaUMlRxhgTOeYLwS6iQYIvJGtVZ9bhj2RHqzA2h7X6hg/RYN@X5ti6JBKkoAWXqMA4d26U3eid9vweosJ5b3g@n2IbLwfeh9O3npiZKUJmJSEmtuSKT0zoi/T9clCj1HXbQafargUOmQeQBVGyidOAQhDFmyQNcuro/rBdObo/rN63TxrFy8TRJEri5ZPG0c4wACvW/@DaUit2qcP5q@dV@or@WoCuHm2w8Visz4qd9RFVyLzAbjAMMMHjLw "JavaScript (Node.js) – Try It Online"