JSFiddle - React, Tailwind, and code Playground

by Saurabh Khemka

HTML

from Uttam Vasishta S M (Cisco) to everyone:    11:20 AM

Here Array with chess board 8x8 matrix. Let’s assume all 1’s are place where king can’t move and 0’s are place where king can move. Find out how many possible move is there for king for given position?
[[1,1,1,1,1,1,1,1],
[1,0,1,1,0,0,1,0],
[1,0,1,0,0,0,1,0],
[1,0,1,1,0,0,1,0],
[1,0,1,1,0,1,1,0],
[1,0,1,1,0,0,1,0],
[1,0,1,1,0,1,1,0],
[1,0,1,1,0,0,1,0]]
Example run below :
Input current king position —> 3,3
[0,1,1],
0,1,0
0,1,1
Output will be —> 4 ( as there are 4 0’s where king can move)

JavaScript

const text = 'Hello world, it is so nice to be alive.';
const changeCase = (str) => {
   const newStr = str
   .split("")
   .map((word, index) => {
      if(index % 2 !== 0){
         return word.toLowerCase();
      }else{
         return word.toUpperCase();
      }
   })
   .join("");
   return newStr;
};
console.log(changeCase(text));