The solution code is written in MoonScript.
import sort, reduce from require "pl.seq" export max_number = => ~~(reduce "..", sort "#{@}"\gmatch".")\reverse!
maxNumber=n=>eval([...n+``].sort().reverse().join``+`n`)- import sort, reduce from require "pl.seq"
- export max_number = => ~~(reduce "..", sort "#{@}"\gmatch".")\reverse!
require "setup" describe("Solution", function() it("should return maximum format of number", function() assert.are.same(4, max_number(4)) assert.are.same(21, max_number(12)) assert.are.same(110, max_number(101), 110) assert.are.same(754000000000000000, max_number(400000005000007000)) assert.are.same(988777666444322200, max_number(307778062924466824)) end) end)
// Since Node 10, we're using Mocha.// You can use `chai` for assertions.const chai = require("chai");const assert = chai.assert;// Uncomment the following line to disable truncating failure messages for deep equals, do:// chai.config.truncateThreshold = 0;// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.// Uncomment the following to use the old assertions:// const Test = require("@codewars/test-compat");- require "setup"
describe("Solution", function() {it("should_return_maximum_format_of_number", function() {assert.strictEqual(maxNumber(4n), 4n);assert.strictEqual(maxNumber(12n), 21n);assert.strictEqual(maxNumber(101n), 110n);assert.strictEqual(maxNumber(400000005000007000n), 754000000000000000n);assert.strictEqual(maxNumber(307778062924466824n), 988777666444322200n);});});- describe("Solution", function()
- it("should return maximum format of number", function()
- assert.are.same(4, max_number(4))
- assert.are.same(21, max_number(12))
- assert.are.same(110, max_number(101), 110)
- assert.are.same(754000000000000000, max_number(400000005000007000))
- assert.are.same(988777666444322200, max_number(307778062924466824))
- end)
- end)
local function find_squares_in_array(arr) local sum = 0 for _, v in ipairs(arr) do sum = sum + v ^ 2 end return sum end return find_squares_in_array
from numpy import square- local function find_squares_in_array(arr)
- local sum = 0
- for _, v in ipairs(arr) do
- sum = sum + v ^ 2
- end
- return sum
- end
def find_squares_in_array(arr):return sum(map(square, arr))- return find_squares_in_array
local find_squares_in_array = require "solution" it("Sample Tests", function() assert.are.same(0, find_squares_in_array {}) assert.are.same(55, find_squares_in_array { 1, 2, 3, 4, 5 }) assert.are.same(16, find_squares_in_array { 4 }) assert.are.same(0, find_squares_in_array { 0, 0, 0, 0 }) end)
from solution import find_squares_in_arrayimport codewars_test as test- local find_squares_in_array = require "solution"
@test.describe("find_squares_in_array")def sample_tests():@test.it('Sample Tests')def sample_tests():test.assert_equals(find_squares_in_array([]), 0)test.assert_equals(find_squares_in_array([1, 2, 3, 4, 5]), 55)test.assert_equals(find_squares_in_array([4]), 16)test.assert_equals(find_squares_in_array([0, 0, 0, 0]), 0)- it("Sample Tests", function()
- assert.are.same(0, find_squares_in_array {})
- assert.are.same(55, find_squares_in_array { 1, 2, 3, 4, 5 })
- assert.are.same(16, find_squares_in_array { 4 })
- assert.are.same(0, find_squares_in_array { 0, 0, 0, 0 })
- end)