Kata of the Day #18

Find the Position

kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
Kata of the Day #18

When provided with a letter, return its position in the alphabet.

TypeScript


function position(alphabet: string): string {
  const position = "abcdefghijklmnopqrstuvwxyz".split('').indexOf(alphabet) + 1;
  return `Position of alphabet: ${position}`;
}

console.log(position("c"));

Go


package main

import (
    "fmt"
    "strings"
)

func position(alphabet string) string {
    position := strings.Index("abcdefghijklmnopqrstuvwxyz", alphabet) + 1
    return fmt.Sprintf("Position of alphabet: %d", position)
}

func main() {
    fmt.Println(position("c"))
}

Python


def position(alphabet):
    position = "abcdefghijklmnopqrstuvwxyz".index(alphabet) + 1
    return f"Position of alphabet: {position}"

print(position("c"))

PHP


function position($alphabet) {
    $position = strpos("abcdefghijklmnopqrstuvwxyz", $alphabet) + 1;
    return "Position of alphabet: $position";
}

echo position("c");

Go to Kata
ByJulie Kohl

Need some help?

Want us to give you some help with your business? No problem, here's a video on who we can help, and how, along with our calendar so you can book in a call to discuss us working together.

Let's see
budget
budget
budget
budget
budget
budget
budget
budget
budget
budget

Subscribe to our newsletter

subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe