Code
Diff
  • export let flip_the_number = (x:number) => +[...""+x].reverse().join('')
    • export let flip_the_number = (x:number) => +[...`${x}`].reverse().join('')
    • export let flip_the_number = (x:number) => +[...""+x].reverse().join('')
Code
Diff
  • const countVowel=s=>(s.match(/[aeiou]/ig) || []).length
      
    • //countVowelAtWord=s=>s.replace(!/[aeiou]/ig,``).length
    • const countVowel=s=>s.replace(/[^aeiou]/ig,'').length
    • const countVowel=s=>(s.match(/[aeiou]/ig) || []).length

return type
shorten a lot

Code
Diff
  • export function reverseInt(n: number): number {
      return +[...""+n].reverse().join("")
    }
    
    
    
    • export function reverseInt(n: number) {
    • return +String(n).replace(/\d/g, (_, i, a) => a.slice(a.length - i - 1, a.length - i))
    • export function reverseInt(n: number): number {
    • return +[...""+n].reverse().join("")
    • }
Code
Diff
  • convert_decimal_binary=lambda i:int(bin(i)[2:])
    • # Actually not using bin function)))
    • convert_decimal_binary=lambda i: int(f"{i:b}")
    • convert_decimal_binary=lambda i:int(bin(i)[2:])

RSpec works as expected with the extra diff message.

Code
Diff
  • puts # "Uncomment the test cases to see the errors"
    • puts "Uncomment the test cases to see the errors"
    • puts # "Uncomment the test cases to see the errors"
Code
Diff
  • const getIDS = n => [...n].reduce((r, x) => r + +x, 0)
    • const getIDS = n => [...n].reduce((r, x) => r + Number(x), 0);
    • const getIDS = n => [...n].reduce((r, x) => r + +x, 0)

One char less ~~

Code
Diff
  • const factorial = n => n < 2 ? 1 : n * factorial(n - 1);
    • const factorial = n => n <= 1 ? 1 : n * factorial(n - 1);
    • const factorial = n => n < 2 ? 1 : n * factorial(n - 1);
Code
Diff
  • export const example = () => !!!!!!!!1
    • export const example = () => false + true
    • export const example = () => !!!!!!!!1

first time programming in C++ ~~

Code
Diff
  • unsigned long long div2(unsigned long long a){
      
      return a / 2;
    }
    • unsigned long long div2(unsigned long long a){
    • //Use binary operators...I-O
    • return a >> 1;
    • return a / 2;
    • }

ruby lambda function

Code
Diff
  • palindrome = ->(x) do
      x.downcase == x.downcase.reverse
    end
    • Palindrome = lambda x: x.lower() == x.lower()[::-1]
    • palindrome = ->(x) do
    • x.downcase == x.downcase.reverse
    • end
Fundamentals
Numbers
Integers

I'm just playing with kumite !!!!!

Code
Diff
  • def is_odd(input)
      input & 1 == 1
    end
    
    • def is_odd(input):
    • return input & 1
    • def is_odd(input)
    • input & 1 == 1
    • end
Fundamentals
Numbers
Integers

I'm just playing around with kumite !!!!!

Code
Diff
  • def is_odd(input):
        return input & 1
    
    • public static class Kata
    • {
    • public static bool IsOdd(int input)
    • {
    • return (input & 1) == 1;
    • }
    • }
    • def is_odd(input):
    • return input & 1
Code
Diff
  • require "prime"
    
    def is_prime(n)
      n.prime?
    end
    • is_prime = lambda n: n == 2 or n > 2 and n % 2 and all(n % i for i in range(3, int(n**.5) + 1, 2))
    • require "prime"
    • def is_prime(n)
    • n.prime?
    • end

All the previous forks are wrong due to the lack of random test cases !!!

Code
Diff
  • is_prime = lambda n: n == 2 or n > 2 and n % 2 and all(n % i for i in range(3, int(n**.5) + 1, 2))
    • is_prime = lambda n: n in (2,3) or n%2 * n%3 * n > 1
    • is_prime = lambda n: n == 2 or n > 2 and n % 2 and all(n % i for i in range(3, int(n**.5) + 1, 2))
Code
Diff
  • def find_first_sub_string(string, substring):
        return string.index(substring) if substring in string else None
    • fun findFirstSubString(string: String, subString: String): Int? {
    • val stringArray = string.toList()
    • val substringArray = subString.toList()
    • if (stringArray.size < substringArray.size || stringArray.isEmpty() || substringArray.isEmpty()) {
    • return null
    • }
    • var counter = 0
    • var startIndex = 0
    • var i = 0
    • while (i < stringArray.size) {
    • if (stringArray[i] == substringArray[counter]) {
    • if(counter == 0) {
    • startIndex = i
    • }
    • if ((counter + 1) == substringArray.size) {
    • return startIndex
    • }
    • counter++
    • i++
    • }
    • else {
    • if (counter > 0) {
    • i = startIndex + 1
    • }
    • else {
    • i++
    • }
    • counter = 0
    • startIndex = 0
    • }
    • println(i)
    • }
    • return null
    • }
    • def find_first_sub_string(string, substring):
    • return string.index(substring) if substring in string else None
Test Cases
Diff
  • test.assert_equals(find_first_sub_string("1234","12"), 0)
    test.assert_equals(find_first_sub_string("012","12"), 1)
    test.assert_equals(find_first_sub_string("4321","21"), 2 )               
    test.assert_equals(find_first_sub_string("ABCDE","21"), None)
    test.assert_equals(find_first_sub_string("","21"), None)
    
    • import org.junit.Assert
    • import org.junit.Test
    • class SimpleSubStringSearchKtTest {
    • @Test
    • fun `Substring longer than string`() {
    • Assert.assertNull(findFirstSubString("12345", "123456"))
    • Assert.assertNull(findFirstSubString("54321", "123456"))
    • }
    • @Test
    • fun `Empty string`() {
    • Assert.assertNull(findFirstSubString("", "123456"))
    • }
    • @Test
    • fun `Empty substring`() {
    • Assert.assertNull(findFirstSubString("12323123", ""))
    • }
    • @Test
    • fun `Empty substring and string`() {
    • Assert.assertNull(findFirstSubString("", ""))
    • }
    • @Test
    • fun `Correct finding`() {
    • Assert.assertEquals(findFirstSubString("12345", "123"), 0)
    • Assert.assertEquals(findFirstSubString("54321321", "321"), 2)
    • Assert.assertEquals(findFirstSubString("123456789ABCDE123456789", "ABCDE"), 9)
    • Assert.assertEquals(findFirstSubString("123456789ABCDE123456789", "A"), 9)
    • Assert.assertEquals(findFirstSubString("123456789ABCDE123456789", "a"), null)
    • Assert.assertEquals(findFirstSubString("111234", "1234"), 2)
    • }
    • }
    • test.assert_equals(find_first_sub_string("1234","12"), 0)
    • test.assert_equals(find_first_sub_string("012","12"), 1)
    • test.assert_equals(find_first_sub_string("4321","21"), 2 )
    • test.assert_equals(find_first_sub_string("ABCDE","21"), None)
    • test.assert_equals(find_first_sub_string("","21"), None)
Loading more items...