金額から金種集計

function(関数):
Sample input(入力例):
Sample output(出力例):
formula(式):

While ( 
    [ 
        ~amount = amount;
        ~denominations = "[
            { \"name\": \"10000\", \"value\": 10000 },
            { \"name\": \"05000\", \"value\": 5000 },
            { \"name\": \"01000\", \"value\": 1000 },
            { \"name\": \"00500\", \"value\": 500 },
            { \"name\": \"00100\", \"value\": 100 },
            { \"name\": \"00050\", \"value\": 50 },
            { \"name\": \"00010\", \"value\": 10 },
            { \"name\": \"00005\", \"value\": 5 },
            { \"name\": \"00001\", \"value\": 1 }
            ]";
	    ~listKey = JSONListKeys ( ~denominations ; "" );
	    ~countListKey = ValueCount ( ~listKey ) ; 
	    ~data = "{}";
	    ~n = 1
    ] ; 
    ~n  ≤  ~countListKey ; 
    [
	    ~obj = JSONGetElement ( ~denominations ; ~n-1 );
	    ~value = JSONGetElement ( ~obj ; "value");
	    ~name = JSONGetElement ( ~obj ; "name");
	    ~count = Int ( ~amount / ~value );
	    ~data = JSONSetElement ( ~data ; ~name ; ~count ; 2 );
	    ~amount = If ( ~count > 0 ; ~amount-(~value*~count); ~amount );
	    ~n = ~n + 1 
    ] ;
    JSONFormatElements ( ~data )
)