Skip to content

Instantly share code, notes, and snippets.

@dubistdu
Created April 16, 2018 21:42
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 dubistdu/83ca0866244b5e45672a9054c011fdc9 to your computer and use it in GitHub Desktop.
Save dubistdu/83ca0866244b5e45672a9054c011fdc9 to your computer and use it in GitHub Desktop.
consonant kata / form the minimum kata

consonant

ruby

def solve(s)
  alphabet = ("a".."z").to_a
  s.tr('aeiou', "*").split("*").map { |a| a.chars.map { |i| alphabet.find_index(i) + 1 }.sum }.max
end

js

function solve(s) {
  let anum= {
        a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10, k: 11, 
        l: 12, m: 13, n: 14,o: 15, p: 16, q: 17, r: 18, s: 19, t: 20, 
        u: 21, v: 22, w: 23, x: 24, y: 25, z: 26
    }
  return Math.max(...s.replace(/[aeiou]/ig, '*').split('*').filter(e => String(e).trim()).map( x => x.split('').map (i => anum[i]).reduce((a,b) => a + b, 0)))
};

Form the minimum

ruby

def min_value(digits)
  digits.uniq.sort.join.to_i
end

js

function minValue(values){
  let unique_values = Array.from(new Set(values)).sort().join("");
  return parseInt(unique_values);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment