Skip to main content

Reverse

Reverses the position of object elements

Functional programming

  • Typing:
() => O
  • Example:
import objectAsArray from "object-as-array";

export default function example() {

const obj = objectAsArray({
I : 1,
V : 5,
X : 10,
L : 50,
C : 100,
D : 500,
M : 1000
});

return obj.reverse();

// Result: {M: 1000, D: 500, C: 100, L: 50, X: 10, V: 5, I: 1}

}

Modular programming

  • Typing:
<O extends object>(object: O) => O
  • Example:
import reverse from "object-as-array/reverse";

export default function example() {

const obj = {
I : 1,
V : 5,
X : 10,
L : 50,
C : 100,
D : 500,
M : 1000
};

return reverse(obj);

// Result: {M: 1000, D: 500, C: 100, L: 50, X: 10, V: 5, I: 1}

}