#29 - Ones' Complement CodeWars Kata (7 Kyu) - DEV Community
Maybe your like
Instructions
The Ones' Complement of a binary number is the number obtained by swapping all the 0s for 1s and all the 1s for 0s. For example:
onesComplement(1001) = 0110 onesComplement(1001) = 0110
For any given binary number,formatted as a string, return the Ones' Complement of that number.
My solution:
function onesComplement(n) { return n.split('').map(n=>n == '0' ? '1' : '0').join('') }; Enter fullscreen mode Exit fullscreen modeExplanation
I splitted the string into an array, and the I mapped it, using a ternary conditional I checked if the number being iterated is '0' it will change it to '0', else it'll change it to '0', and at the end I just joined the array.
What do you think about this solution? 👇🤔
My Github My twitter Solve this Kata
Templates let you quickly answer FAQs or store snippets for re-use.
Submit Preview Dismiss Code of Conduct • Report abuseAre you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
Cesar Del rio Follow Join me on my road to mastering coding. 100 days of codewars challenge. - Location México
- Work CEO at Mercurio Agencia Digital
- Joined Dec 29, 2021
We're a place where coders share, stay up-to-date and grow their careers.
Log in Create accountTag » Codewars 7 Kyu Solutions Javascript
-
CodeWars-7-kata - GitHub
-
CodeWars-7-kyu-Soluitions-part-2 - GitHub
-
GitHub - GitHub
-
Codewars 7 Kyu Least Larger Javascript - YouTube
-
Codewars 7 Kyu Challenge Four/Seven In JavaScript - YouTube
-
Codewars 7 Kyu Simple Fun #213: Is Function? JavaScript - YouTube
-
7 Kyu - Codewars
-
Codewars-javascript · GitHub Topics
-
CodeWars-7-kyu-Soluitions-part-2 Summary - Kandi
-
Solutions To Codewars Kata: 7 Kyu - Pythonatrix
-
Solving Code Wars Problem In Javascript (ES6) [7th Kyu]
-
Codewars · GitHub Topics
-
Codewars-solutions Github
-
Codewars/ - Gitter