export const flip_the_number = (x: number): number => { return Number(Array.from(x.toString()).reduce((acc, s) => s + acc, "")); }
fn flip_the_number(x: &u64) -> u64 {let mut x = *x;let mut y = 0;while x != 0 {y = y * 10 + x % 10;x /= 10;}y- export const flip_the_number = (x: number): number => {
- return Number(Array.from(x.toString()).reduce((acc, s) => s + acc, ""));
- }
// See https://www.chaijs.com for how to use Chai. import { assert } from "chai"; import { flip_the_number } from "./solution"; describe("Flipped numbers", () => { it("should be valid", () => { assert.strictEqual(flip_the_number(12345), 54321); assert.strictEqual(flip_the_number(11121), 12111); assert.strictEqual(flip_the_number(0), 0); assert.strictEqual(flip_the_number(1.0), 1); assert.strictEqual(flip_the_number(9.12345), 54321.9); assert.strictEqual(flip_the_number(9007199254740991), 1990474529917009); }); });
#[test]fn test() {let nums = [(1234, 4321),(1234567890, 987654321),(243, 342),(12, 21),(837583, 385738),(32851532, 23515823),(999999, 999999),(111, 111),(35832456789, 98765423853),(9223372036854775807, 7085774586302733229)];for num in nums.iter() {assert_eq!(num.1, flip_the_number(&num.0));}}- // See https://www.chaijs.com for how to use Chai.
- import { assert } from "chai";
- import { flip_the_number } from "./solution";
- describe("Flipped numbers", () => {
- it("should be valid", () => {
- assert.strictEqual(flip_the_number(12345), 54321);
- assert.strictEqual(flip_the_number(11121), 12111);
- assert.strictEqual(flip_the_number(0), 0);
- assert.strictEqual(flip_the_number(1.0), 1);
- assert.strictEqual(flip_the_number(9.12345), 54321.9);
- assert.strictEqual(flip_the_number(9007199254740991), 1990474529917009);
- });
- });