Write Up Code Wars — Shifter Words Solutions JavaScript


You probably know that some characters written on a piece of paper, after turning this sheet 180 degrees, can be read, although sometimes in a different way. So, uppercase letters "H", "I", "N", "O", "S", "X", "Z" after rotation are not changed, the letter "M" becomes a "W", and Vice versa, the letter "W" becomes a "M".We will call a word "shifter" if it consists only of letters "H", "I", "N", "O", "S", "X", "Z", "M" and "W". After turning the sheet, this word can also be read, although in a different way. So, the word "WOW "turns into the word "MOM". On the other hand, the word "HOME" is not a shifter.Find the number of unique shifter words in the input string (without duplicates). String contains only uppercase letters.


shifter("SOS IN THE HOME") === 2 // shifter words are "SOS" and "IN"
shifter("WHO IS SHIFTER AND WHO IS NO") === 3 // shifter words are "WHO", "IS", "NO"
shifter("TASK") === 0 // no shifter words
shifter("") === 0 // no shifter words in empty string

My Answer

const base = ["H", "I", "N", "O", "S", "X", "Z", "M", "W"];
arrays = [...new Set(str.split(" "))];
let counter = 0;if (str.length === 0) arrays = [];
arrays.forEach((word) => {console.log(word);let check = word.split("").every((letter) => base.includes(letter));if (check) counter++;});
return counter;


A Stoic Web Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store