plus/oop/reverse.js
/**
 * It reverses the given object, i.e. return a copy of the object 
 * where the keys have become the values and the values the keys
 * 
 * @param {object} o the object
 * @returns {object} the new object
 */
It reverses the given object, i.e. return a copy of the object
where the keys have become the values and the values the keys


It reverses the given object i . e . return a copy of the object where the keys have become the values and the values the keys
function reverse(o) {
    if (typeof o !== 'object') {
        throw new Error("not an object");
    }
    let result = {};
    let keys = Object.keys(o);
    for(const key of keys){
        const value = o[key];
        result[value] = key;
    }
    return result;
}
function reverse ( o ) { if ( typeof o !== 'object' ) { throw new Error ( "not an object" ) ; } let result = { } ; let keys = Object . keys ( o ) ; for ( const key of keys ) { const value = o [ key ] ; result [ value ] = key ; } return result ; }
It reverses the given object, i.e.
It reverses the given object i . e .