Ad
Control Flow
Basic Language Features
Fundamentals
Code
Diff
  • module Nigelius where
    
    getBonusDamage :: Integer -> Integer
    getBonusDamage = (^2).(`div`250)
    
    • module Nigelius where
    • getBonusDamage :: Integer -> Integer
    • getBonusDamage = flip (^) 2 . flip div 250
    • getBonusDamage = (^2).(`div`250)

Tests added.

Code
Diff
  • const returnAscending=n=>[...n+''].sort().reduce((a,b)=>a*10+ +b,0);
    
    • function returnAscending(n){
    • return +(n+'').split('').sort(function(a,b){return a-b }).join('');
    • }
    • const returnAscending=n=>[...n+''].sort().reduce((a,b)=>a*10+ +b,0);

Now with tests shipped.

Code
Diff
  • const returnAscending = (...args) => args.sort((a,b)=> a-b ).join('');
    • const returnAscending = (...args) => args.sort(function(a,b){return a-b }).join('');
    • const returnAscending = (...args) => args.sort((a,b)=> a-b ).join('');

Removed null check from random tests.

Code
Diff
  • module FindMaxNumber where
    
    import Data.List.NonEmpty
    
    find_max :: Ord a => NonEmpty a -> a
    find_max (x:|xs) = foldr max x xs
    
    • module FindMaxNumber where
    • import Data.List.NonEmpty
    • find_max :: Ord a => NonEmpty a -> a
    • find_max (x:|xs) = foldr (\ a b -> if a > b then a else b) x xs
    • find_max (x:|xs) = foldr max x xs
Code
Diff
  • module FindMaxNumber where
    
    find_max :: Ord a => [a] -> a
    find_max [] = error "find_max: Empty list"
    find_max (x:xs) = foldr (\ a b -> if a > b then a else b) x xs
    
    • module FindMaxNumber where
    • find_max :: Ord a => [a] -> a
    • find_max = maximum
    • find_max [] = error "find_max: Empty list"
    • find_max (x:xs) = foldr (\ a b -> if a > b then a else b) x xs
Code
Diff
  • def isIterable(l):
        if isinstance(l, str):
            return False
        try:
            l[0]
            return True
        except:
            return False
        
    def unpackList(l):
        output = []
        stack = l
    
        while stack != []:
            val = stack.pop()
            if isIterable(val):
                stack += list(val)
            else:
                output.append(str(val))
    
        return ' '.join(output[::-1])
    
    • def isIterable(l):
    • if isinstance(l, str):
    • return False
    • try:
    • l[0]
    • return True
    • except:
    • return False
    • def unpackIterable(l):
    • def unpackList(l):
    • output = []
    • for item in l:
    • if isIterable(item) and not isinstance(item, str):
    • output += unpackIterable(item)
    • else:
    • output.append(item)
    • return output
    • stack = l
    • def unpackList(l):
    • outputList = []
    • for item in l:
    • if isIterable(item) and not isinstance(item, str):
    • outputList += unpackIterable(item)
    • while stack != []:
    • val = stack.pop()
    • if isIterable(val):
    • stack += list(val)
    • else:
    • outputList.append(item)
    • return " ".join(map(str, outputList))
    • output.append(str(val))
    • return ' '.join(output[::-1])