sampleObj

Returns a sample object with the specified keys and values as random numbers.

1. Code

const sampleObj = (...keys: string[]) => {
  const obj: any = {};
  keys.forEach((key) => {
    obj[key] = Math.random();
  });
  return obj as Record<string, number>;
};

export default sampleObj;

2. Installation

npx @jrtilak/lazykit@latest add sampleObj

3. Description

The sampleObj function takes any number of string arguments, treats each argument as a key, and creates an object where each key is associated with a random number value. The function then returns this object.

4. Props

Prop

Type

Default Value

keys*string[]---

5. Examples

import sampleObj from ".";

const keys = ["key1", "key2", "key3"];
const obj = sampleObj(...keys);
console.log(obj);
// Expected output: { key1: Number, key2: Number, key3: Number }
// Where Number is a random number between 0 and 1.