text: import * as lamb from "../..";
  import { nonFunctions, wannabeEmptyArrays } from "../../__tests__/commons";
  
  describe("index / indexBy", function () {
      var getCity = lamb.getKey("city");
  
      var persons = [
          { name: "Jane", surname: "Doe", age: 12, city: "New York" },
          { name: "John", surname: "Doe", age: 40, city: "New York" },
          { name: "Mario", surname: "Rossi", age: 18, city: "Rome" },
          { name: "Paolo", surname: "Bianchi", age: 15 }
      ];
  
      var personsByAgeIndex = {
          12: { name: "Jane", surname: "Doe", age: 12, city: "New York" },
          15: { name: "Paolo", surname: "Bianchi", age: 15 },
          18: { name: "Mario", surname: "Rossi", age: 18, city: "Rome" },
          40: { name: "John", surname: "Doe", age: 40, city: "New York" }
      };
  
      var personsByCityIndex = {
          "New York": { name: "John", surname: "Doe", age: 40, city: "New York" },
          Rome: { name: "Mario", surname: "Rossi", age: 18, city: "Rome" },
          undefined: { name: "Paolo", surname: "Bianchi", age: 15 }
      };
  
      it("should build a lookup table with keys generated by the iteratee and one value for each key from the original list", function () {
          var indexByAge = function (person, idx, list) {
              expect(list).toBe(persons);
              expect(persons[idx]).toBe(person);
  
              return person.age;
          };
  
          expect(lamb.index(persons, indexByAge)).toEqual(personsByAgeIndex);
          expect(lamb.indexBy(indexByAge)(persons)).toEqual(personsByAgeIndex);
      });
  
      it("should use the last evaluated value when the iteratee produces a duplicate key", function () {
          expect(lamb.index(persons, getCity)).toEqual(personsByCityIndex);
          expect(lamb.indexBy(getCity)(persons)).toEqual(personsByCityIndex);
      });
  
      it("should work with array-like objects", function () {
          var result = {
              h: "h", e: "e", l: "l", o: "o", " ": " ", w: "w", r: "r", d: "d"
          };
  
          expect(lamb.index("hello world", lamb.identity)).toEqual(result);
          expect(lamb.indexBy(lamb.identity)("hello world")).toEqual(result);
      });
  
      it("should consider deleted or unassigned indexes in sparse arrays as `undefined` values", function () {
          var arr = [1, , 3, void 0, 5]; // eslint-disable-line no-sparse-arrays
          var result = { 0: 1, 1: void 0, 2: 3, 3: void 0, 4: 5 };
  
          expect(lamb.index(arr, lamb.getArgAt(1))).toStrictEqual(result);
          expect(lamb.indexBy(lamb.getArgAt(1))(arr)).toStrictEqual(result);
      });
  
      it("should throw an exception if the iteratee isn't a function", function () {
          nonFunctions.forEach(function (value) {
              expect(function () { lamb.index(persons, value); }).toThrow();
              expect(function () { lamb.indexBy(value)(persons); }).toThrow();
          });
  
          expect(function () { lamb.index(persons); }).toThrow();
          expect(function () { lamb.indexBy()(persons); }).toThrow();
      });
  
      it("should throw an exception if called without the data argument", function () {
          expect(lamb.index).toThrow();
          expect(lamb.indexBy(lamb.identity)).toThrow();
      });
  
      it("should throw an exception if supplied with `null` or `undefined`", function () {
          expect(function () { lamb.index(null, lamb.identity); }).toThrow();
          expect(function () { lamb.index(void 0, lamb.identity); }).toThrow();
          expect(function () { lamb.indexBy(lamb.identity)(null); }).toThrow();
          expect(function () { lamb.indexBy(lamb.identity)(void 0); }).toThrow();
      });
  
      it("should treat every other value as an empty array and return an empty object", function () {
          wannabeEmptyArrays.forEach(function (value) {
              expect(lamb.indexBy(lamb.identity)(value)).toEqual({});
              expect(lamb.index(value, lamb.identity)).toEqual({});
          });
      });
  });
  