From 32f1e3351c00b55efe0ebf87916f5aaf6e015e42 Mon Sep 17 00:00:00 2001 From: Dhana D <39583785+ddhira123@users.noreply.github.com> Date: Sun, 24 Oct 2021 15:56:56 +0700 Subject: [PATCH] merge: Added Hex to Binary conversion (#805) * Added Hex to Binary conversion * Update Conversions/HexToBinary.js Co-authored-by: Rak Laptudirm * Update Conversions/HexToBinary.js Co-authored-by: Rak Laptudirm * Update Conversions/HexToBinary.js Co-authored-by: Rak Laptudirm * Update Conversions/HexToBinary.js Co-authored-by: Rak Laptudirm * Fix errors * fix: typo Co-authored-by: Rak Laptudirm --- Conversions/HexToBinary.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Conversions/HexToBinary.js b/Conversions/HexToBinary.js index b67b00c82..2334954f9 100644 --- a/Conversions/HexToBinary.js +++ b/Conversions/HexToBinary.js @@ -21,17 +21,14 @@ const binLookup = (c) => { } const hexToBinary = (hexString) => { /* - Function for convertung Hex to Binary + Function for converting Hex to Binary 1. We convert every hexadecimal bit to 4 binary bits 2. Conversion goes by searching in the lookup table */ - - let result = '' - hexString = hexString.split('') - hexString.forEach(c => { result += binLookup(c) }) - return result + const hexLexemes = hexString.split('') + return hexLexemes.map(lexeme => binLookup(lexeme)).join('') } export default hexToBinary