Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ***Checkout the section 2 for working code***
- // Section 1:
- // let lengths = prompt("Enter Length of the string");
- // let data = [];
- //
- // if (data.lenght < 2) {
- // alert("Please Enter Length 2 or more");
- // } else {
- // for (var i = 0; i <= lengths.length; i++) {
- // let stringData = prompt("Enter Characters");
- // data.push(stringData);
- // }
- // console.log(`You entered data ${data}`);
- // let fchar = data[0];
- // console.log('first char: ' + fchar)
- // console.log(`last char: ${data.length}`)
- // let lchar = data.length
- // console.log('lchar :' + lchar)
- // // let lenlchar = data.length;
- //
- //
- //
- //
- //
- //
- //
- // console.log('lenlchar :' + lenlchar)
- // console.log('test', data[lenlchar])
- // // var lchar = data[lenlchar]
- // console.log('first char: ' + fchar);
- // console.log('lastchar :', + lchar);
- //
- //
- //
- // if (fchar == lchar) {
- // console.log("proceed");
- // } else {
- // console.log("Exit");
- // }
- // // if(data[0] === 'a') {
- // // console.log('a')
- // // }
- // // let lengthofData = data.length
- // // console.log(`Length of Array Data : ${lengthofData}`);
- // //
- // // let halfTheArray = lengthofData / 2
- // // console.log(halfTheArray);
- // }
- // ===================================================================================================================
- // Section 2:
- // Efficient code to check Entered any type of data whether its palindrom or not!
- // past this code in Google Chrome Dev tool's console to check real-quick
- // Inputes: 1: AABCCBAA (Strig data)
- // 2: 123321 (numbers)
- // 3: ?--? (symbols)
- palindrom = str => {
- let originalString = str;
- console.log(`Original String you enterd: ${originalString}`);
- let reverseString = originalString
- .split("")
- .reverse()
- .join("");
- console.log(`Reverse String: ${reverseString}`);
- if (reverseString === originalString) {
- alert(`Yes ${originalString} is Pladindrom ${reverseString}`);
- } else {
- alert(`${originalString} is not a plaindrom`);
- }
- };
- let userInput = prompt("Enter String Here to check Palindrom or NOT");
- if (userInput.length >= 2) {
- console.log(palindrom(userInput));
- } else {
- alert("Please Enter valide data to check palindrom or NOT !!");
- }
Add Comment
Please, Sign In to add comment