Skip to content

Instantly share code, notes, and snippets.

@Risyandi
Created March 14, 2024 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Risyandi/479be9dcfdad051f6dba9ae1282fadd5 to your computer and use it in GitHub Desktop.
Save Risyandi/479be9dcfdad051f6dba9ae1282fadd5 to your computer and use it in GitHub Desktop.
palindrome code test for eigerindo
// checking if the text is palindrome
function palindrome(string) {
let result = true;
let lengthString = string.length;
let indexJ = lengthString - 1;
for (let index = 0; index < lengthString / 2; index++) {
if (string[index] != string[indexJ]) {
result = false;
}
indexJ--;
}
// result log
console.log(result, 'result');
return result;
}
let stringText = 'satas';
palindrome(stringText);
@Risyandi
Copy link
Author

Risyandi commented Apr 5, 2024

package main

// import library 
import(
  "strconv"
)

// Solution is your solution code.
func Solution (num int) bool {

  // created by @risyandi 2024
  // 1. convert parameter "num" of integer to a string
  // 2. get length of the string
  // 3. iterate trough the string to the end
  // 4. compare character in the string from the start and end of string
  // 5. if the result compare not same return value false and if result compare same return true
  
  numberToString := strconv.Itoa(num)
  lengthOfString := len(numberToString)

  for index := 0; index < lengthOfString/2; index++ {
    indexJ := (lengthOfString - 1) - index 
    if numberToString[index] != numberToString[indexJ] {
      return false
    }
  }

  return true
}

using programming language golang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment