← Back to challenges

Word to Bitstring to Boolean Array

JavaScriptHardstringsobjectsarrays

Instructions

Create a function that converts 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("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("loves") ➞ [false, true, false, true, true]

toBoolArray("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.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.