JSFiddle - React, Tailwind, and code Playground

by Aaron Zhang

JavaScript

(function () {
    'use strict';

    function interest(stars, cost) {
        if (cost < 5) { // cost not < 5 continue
            return 'very';
        }
        if (cost >= 12) {
            return 'not interested';
        }
        if (stars === 5) {
            return 'very';
        }
        if (stars > 1) {
            return 'sort-of';
        }
        return 'not interested';
    }


    function generatePair(stars, price) {
        var result = [];
        for (var i = 0; i < stars.length; ++i) {
            for (var j = 0; j < price.length; ++j) {
                result.push([stars[i], price[j]]);
            }
        }
        return result;
    }

    var stars = [1, 2, 3, 4, 5];
    var price = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];

    var testInput = generatePair(stars, price);
    for (var i = 0; i < testInput.length; ++i) {
        var _stars = testInput[i][0];
        var _price = testInput[i][1];

        var string = 'Test Case ' + (i + 1) + '\n' + 'Stars: ' + _stars + ' Cost: ' + _price + '\nresult: ' + interest(_stars, _price) + '\n=========================================\n';
        console.log(string);
    }
})();