class Common {
    // program to convert decimal to binary
    convertToBinary(x) {
        if (x !== 1) {
            let bin = 0;
            let rem, i = 1, step = 1;
            while (x != 0) {
                rem = x % 2;
                x = parseInt(x / 2);
                bin = bin + rem * i;
                i = i * 10;
            }
            console.log(String(bin))
            return String(bin)
        } else {
            console.log('01')
            return '01'
        }


    }

    // Get which channels
    async checkWhichChannelsIsTrue(bin) {
        var channels = [];

        for (let index = 0; index < bin.length; index++) {
            if (bin[index] === '1') {
                channels.push(index + 1);
            }
        }

        return await Promise.all(channels)
    }

    /* 1 = Fall Detection, 2 = N/A */
    async detectionHandler(channels) {
        var detection = ''
        for (var i = 0; i < channels.length; i++) {
         
            switch (channels[i]) {
                case 1:
                    detection += 'Fall Detection,'
                    break;
                case 2:
                    detection += ' N/A,'
                    break;
                default:
                    break
            }
        }
        detection = detection.slice(0, -1);
        detection = detection.substring(0, 0) + detection.substring(1, detection.length);
        return detection
    }
}
export default Common