@softchef/cdk-iot-device-management
Version:
IoT device management is composed of things, thing types, thing groups, jobs, files API services. The constructs can be used independently, that are based on full-managed service to create an API Gateway & Lambda function.
41 lines (32 loc) • 794 B
JavaScript
/* eslint no-constant-condition: 0 */
/**
* Obliterator Take Into Function
* ===============================
*
* Same as the take function but enables the user to select an array class
* in which to insert the retrieved values.
*/
/**
* Take Into.
*
* @param {function} ArrayClass - Array class to use.
* @param {Iterator} iterator - Target iterator.
* @param {number} n - Number of items to take.
* @return {array}
*/
module.exports = function takeInto(ArrayClass, iterator, n) {
var array = new ArrayClass(n),
step,
i = 0;
while (true) {
if (i === n)
return array;
step = iterator.next();
if (step.done) {
if (i !== n)
return array.slice(0, i);
return array;
}
array[i++] = step.value;
}
};