Word to Bitstring to Boolean Array

Published by Deep Xavier in

Create two functions that convert a word to a bitstring and then to a boolean array based on the following criteria:

  1. Locate the position of the letter in the English alphabet (from 1 to 26).
  2. Odd positions will be represented as 1 and even positions will be represented as 0.
  3. Convert the represented positions to boolean values, 1 for true and 0 for false.
  4. Store the conversions into an array.

Examples

toBoolArray(toBitString("deep")) ➞ [false, true, true, false]
// deep converts to 0110
// d is the 4th alphabet - 0
// e is the 5th alphabet - 1
// e is the 5th alphabet - 1
// p is the 16th alphabet - 0

toBoolArray(toBitString("loves")) ➞ [false, true, false, true, true]

toBoolArray(toBitString("tesh")) ➞ [false, true, true, false]

Notes

  • The letter A is at position 1 and Z at 26.
  • All input strings are in lowercase letters of the English alphabet.
Watch a quick demo on how Edabit works.