Ad
Code
Diff
  • module Sum (Sum.sum) where
    
    import Prelude hiding (sum)
    
    sum :: (Foldable t) => t Integer -> Integer
    sum = foldr (+) 0
    • module Sum (Sum.sum) where
    • import Prelude hiding (sum)
    • sum :: (Foldable t) => t Integer -> Integer
    • sum xs | null xs = 0 | otherwise = foldr1 (+) xs
    • sum = foldr (+) 0
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
Data Types
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
Data Types
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))
Loading more items...