improvise code explaination part
Browse files- index.html +214 -38
index.html
CHANGED
|
@@ -615,70 +615,246 @@ const code = document.getElementById('codeInput').value;
|
|
| 615 |
</script>
|
| 616 |
<!-- Enhanced Code Explanation Section -->
|
| 617 |
<div class="py-16 px-4 sm:px-6 lg:px-8 max-w-7xl mx-auto bg-gradient-to-br from-gray-800/50 to-gray-900/60 rounded-lg border border-gray-700/50">
|
| 618 |
-
<div class="text-center mb-12">
|
| 619 |
<h2 class="text-3xl font-extrabold text-white sm:text-4xl">
|
| 620 |
-
<span class="gradient-text">Code Explanation</span>
|
| 621 |
</h2>
|
| 622 |
<p class="mt-3 max-w-2xl mx-auto text-lg text-gray-300">
|
| 623 |
-
Our AI
|
| 624 |
</p>
|
| 625 |
</div>
|
| 626 |
|
| 627 |
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 631 |
</div>
|
| 632 |
<div id="codeExplanation" class="text-gray-300 text-sm font-mono space-y-4">
|
| 633 |
-
<div>
|
| 634 |
-
<div class="
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
<div class="
|
| 639 |
-
|
|
|
|
|
|
|
|
|
|
| 640 |
</div>
|
| 641 |
-
<div>
|
| 642 |
-
<div class="
|
| 643 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 644 |
</div>
|
| 645 |
-
<div>
|
| 646 |
-
<div class="
|
| 647 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 648 |
</div>
|
| 649 |
</div>
|
| 650 |
</div>
|
| 651 |
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 655 |
</div>
|
| 656 |
-
<div class="text-gray-300 text-sm font-mono space-y-4">
|
| 657 |
-
<div class="
|
| 658 |
-
<
|
| 659 |
-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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 682 |
|
| 683 |
<!-- CTA Section -->
|
| 684 |
<div class="bg-gradient-to-r from-primary/20 to-secondary/20 py-16 px-4 sm:px-6 lg:px-8">
|
|
|
|
| 615 |
</script>
|
| 616 |
<!-- Enhanced Code Explanation Section -->
|
| 617 |
<div class="py-16 px-4 sm:px-6 lg:px-8 max-w-7xl mx-auto bg-gradient-to-br from-gray-800/50 to-gray-900/60 rounded-lg border border-gray-700/50">
|
| 618 |
+
<div class="text-center mb-12">
|
| 619 |
<h2 class="text-3xl font-extrabold text-white sm:text-4xl">
|
| 620 |
+
<span class="gradient-text">AI-Powered Code Explanation</span>
|
| 621 |
</h2>
|
| 622 |
<p class="mt-3 max-w-2xl mx-auto text-lg text-gray-300">
|
| 623 |
+
Our AI analyzes your code structure, logic flow, and provides actionable insights.
|
| 624 |
</p>
|
| 625 |
</div>
|
| 626 |
|
| 627 |
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
|
| 628 |
+
<!-- Interactive Code Breakdown -->
|
| 629 |
+
<div class="code-editor p-4 glow">
|
| 630 |
+
<div class="flex items-center justify-between mb-4">
|
| 631 |
+
<div class="text-sm text-gray-400">Interactive Code Breakdown</div>
|
| 632 |
+
<button onclick="toggleComplexity()" class="text-xs bg-gray-700/50 hover:bg-gray-600/70 text-gray-300 px-3 py-1 rounded-full">
|
| 633 |
+
<span id="complexityToggle">Show Advanced</span>
|
| 634 |
+
</button>
|
| 635 |
</div>
|
| 636 |
<div id="codeExplanation" class="text-gray-300 text-sm font-mono space-y-4">
|
| 637 |
+
<div class="bg-gray-800/50 p-3 rounded-lg border-l-4 border-primary">
|
| 638 |
+
<div class="flex items-center">
|
| 639 |
+
<i data-feather="chevron-right" class="text-primary mr-2"></i>
|
| 640 |
+
<div class="text-primary font-medium">Function Declaration</div>
|
| 641 |
+
</div>
|
| 642 |
+
<div class="mt-2 ml-6 text-gray-400">
|
| 643 |
+
<p>• Public function: calculateTotal(items)</p>
|
| 644 |
+
<p>• Accepts single parameter: items array</p>
|
| 645 |
+
<p>• Implicit return type: Number</p>
|
| 646 |
+
</div>
|
| 647 |
</div>
|
| 648 |
+
<div class="bg-gray-800/50 p-3 rounded-lg border-l-4 border-red-400">
|
| 649 |
+
<div class="flex items-center">
|
| 650 |
+
<i data-feather="shield" class="text-red-400 mr-2"></i>
|
| 651 |
+
<div class="text-red-400 font-medium">Input Validation</div>
|
| 652 |
+
</div>
|
| 653 |
+
<div class="mt-2 ml-6 text-gray-400">
|
| 654 |
+
<p>• Type check: Array.isArray()</p>
|
| 655 |
+
<p>• Throws Error on invalid input</p>
|
| 656 |
+
<p>• Missing: Element validation</p>
|
| 657 |
+
</div>
|
| 658 |
</div>
|
| 659 |
+
<div class="bg-gray-800/50 p-3 rounded-lg border-l-4 border-yellow-400">
|
| 660 |
+
<div class="flex items-center">
|
| 661 |
+
<i data-feather="repeat" class="text-yellow-400 mr-2"></i>
|
| 662 |
+
<div class="text-yellow-400 font-medium">Iteration Logic</div>
|
| 663 |
+
</div>
|
| 664 |
+
<div class="mt-2 ml-6 text-gray-400">
|
| 665 |
+
<p>• Array traversal: forEach</p>
|
| 666 |
+
<p>• Type coercion: Number()</p>
|
| 667 |
+
<p>• Default quantity: 1</p>
|
| 668 |
+
</div>
|
| 669 |
</div>
|
| 670 |
</div>
|
| 671 |
</div>
|
| 672 |
|
| 673 |
+
<!-- Advanced Analysis & Metrics -->
|
| 674 |
+
<div class="code-editor p-4 glow">
|
| 675 |
+
<div class="flex items-center justify-between mb-4">
|
| 676 |
+
<div class="text-sm text-gray-400">Advanced Analysis & Metrics</div>
|
| 677 |
+
<div class="flex space-x-2">
|
| 678 |
+
<button onclick="showPerformance()" class="text-xs bg-gray-700/50 hover:bg-gray-600/70 text-gray-300 px-3 py-1 rounded-full">Performance</button>
|
| 679 |
+
<button onclick="showSecurity()" class="text-xs bg-gray-700/50 hover:bg-gray-600/70 text-gray-300 px-3 py-1 rounded-full">Security</button>
|
| 680 |
+
<button onclick="showBestPractices()" class="text-xs bg-gray-700/50 hover:bg-gray-600/70 text-gray-300 px-3 py-1 rounded-full">Best Practices</button>
|
| 681 |
+
</div>
|
| 682 |
</div>
|
| 683 |
+
<div id="analysisMetrics" class="text-gray-300 text-sm font-mono space-y-4">
|
| 684 |
+
<div class="bg-gray-800/50 p-3 rounded-lg">
|
| 685 |
+
<div class="flex items-center justify-between">
|
| 686 |
+
<div class="font-medium flex items-center">
|
| 687 |
+
<i data-feather="clock" class="text-blue-400 mr-2"></i>
|
| 688 |
+
<span>Time Complexity</span>
|
| 689 |
+
</div>
|
| 690 |
+
<span class="text-green-400 text-xs bg-green-400/10 px-2 py-0.5 rounded-full">O(n)</span>
|
| 691 |
+
</div>
|
| 692 |
+
<div class="mt-2 text-gray-400">
|
| 693 |
+
<p>• Linear time operation based on input size</p>
|
| 694 |
+
<p>• No nested loops or recursive calls</p>
|
| 695 |
</div>
|
| 696 |
</div>
|
| 697 |
+
<div class="bg-gray-800/50 p-3 rounded-lg">
|
| 698 |
+
<div class="flex items-center justify-between">
|
| 699 |
+
<div class="font-medium flex items-center">
|
| 700 |
+
<i data-feather="cpu" class="text-purple-400 mr-2"></i>
|
| 701 |
+
<span>Memory Usage</span>
|
| 702 |
+
</div>
|
| 703 |
+
<span class="text-yellow-400 text-xs bg-yellow-400/10 px-2 py-0.5 rounded-full">O(1)</span>
|
| 704 |
+
</div>
|
| 705 |
+
<div class="mt-2 text-gray-400">
|
| 706 |
+
<p>• Constant space complexity</p>
|
| 707 |
+
<p>• Only primitive variables used</p>
|
| 708 |
</div>
|
| 709 |
</div>
|
| 710 |
+
<div class="bg-gray-800/50 p-3 rounded-lg">
|
| 711 |
+
<div class="flex items-center justify-between">
|
| 712 |
+
<div class="font-medium flex items-center">
|
| 713 |
+
<i data-feather="alert-triangle" class="text-red-400 mr-2"></i>
|
| 714 |
+
<span>Potential Issues</span>
|
| 715 |
+
</div>
|
| 716 |
+
<span class="text-red-400 text-xs bg-red-400/10 px-2 py-0.5 rounded-full">2 found</span>
|
| 717 |
+
</div>
|
| 718 |
+
<div class="mt-2 text-gray-400">
|
| 719 |
+
<p>• Floating point precision (currency)</p>
|
| 720 |
+
<p>• No input sanitization</p>
|
| 721 |
</div>
|
| 722 |
</div>
|
| 723 |
</div>
|
| 724 |
</div>
|
| 725 |
</div>
|
| 726 |
</div>
|
| 727 |
+
<script>
|
| 728 |
+
function toggleComplexity() {
|
| 729 |
+
const toggle = document.getElementById('complexityToggle');
|
| 730 |
+
const explanation = document.getElementById('codeExplanation');
|
| 731 |
+
|
| 732 |
+
if (toggle.textContent === 'Show Advanced') {
|
| 733 |
+
toggle.textContent = 'Show Basic';
|
| 734 |
+
// Add advanced explanations
|
| 735 |
+
explanation.innerHTML += `
|
| 736 |
+
<div class="bg-gray-800/50 p-3 rounded-lg border-l-4 border-green-400">
|
| 737 |
+
<div class="flex items-center">
|
| 738 |
+
<i data-feather="code" class="text-green-400 mr-2"></i>
|
| 739 |
+
<div class="text-green-400 font-medium">Advanced Analysis</div>
|
| 740 |
+
</div>
|
| 741 |
+
<div class="mt-2 ml-6 text-gray-400">
|
| 742 |
+
<p>• Potential race conditions: None</p>
|
| 743 |
+
<p>• Memory leaks: Unlikely</p>
|
| 744 |
+
<p>• Side effects: Pure function</p>
|
| 745 |
+
</div>
|
| 746 |
+
</div>
|
| 747 |
+
`;
|
| 748 |
+
} else {
|
| 749 |
+
toggle.textContent = 'Show Advanced';
|
| 750 |
+
// Remove advanced explanations
|
| 751 |
+
const advanced = explanation.querySelector('.border-l-4.border-green-400');
|
| 752 |
+
if (advanced) advanced.remove();
|
| 753 |
+
}
|
| 754 |
+
feather.replace();
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
function showPerformance() {
|
| 758 |
+
const metrics = document.getElementById('analysisMetrics');
|
| 759 |
+
metrics.innerHTML = `
|
| 760 |
+
<div class="bg-gray-800/50 p-3 rounded-lg">
|
| 761 |
+
<div class="flex items-center justify-between">
|
| 762 |
+
<div class="font-medium flex items-center">
|
| 763 |
+
<i data-feather="clock" class="text-blue-400 mr-2"></i>
|
| 764 |
+
<span>Time Complexity</span>
|
| 765 |
+
</div>
|
| 766 |
+
<span class="text-green-400 text-xs bg-green-400/10 px-2 py-0.5 rounded-full">O(n)</span>
|
| 767 |
+
</div>
|
| 768 |
+
<div class="mt-2 text-gray-400">
|
| 769 |
+
<p>• Linear time operation based on input size</p>
|
| 770 |
+
<p>• No nested loops or recursive calls</p>
|
| 771 |
+
</div>
|
| 772 |
+
</div>
|
| 773 |
+
<div class="bg-gray-800/50 p-3 rounded-lg">
|
| 774 |
+
<div class="flex items-center justify-between">
|
| 775 |
+
<div class="font-medium flex items-center">
|
| 776 |
+
<i data-feather="cpu" class="text-purple-400 mr-2"></i>
|
| 777 |
+
<span>Memory Usage</span>
|
| 778 |
+
</div>
|
| 779 |
+
<span class="text-yellow-400 text-xs bg-yellow-400/10 px-2 py-0.5 rounded-full">O(1)</span>
|
| 780 |
+
</div>
|
| 781 |
+
<div class="mt-2 text-gray-400">
|
| 782 |
+
<p>• Constant space complexity</p>
|
| 783 |
+
<p>• Only primitive variables used</p>
|
| 784 |
+
</div>
|
| 785 |
+
</div>
|
| 786 |
+
`;
|
| 787 |
+
feather.replace();
|
| 788 |
+
}
|
| 789 |
+
|
| 790 |
+
function showSecurity() {
|
| 791 |
+
const metrics = document.getElementById('analysisMetrics');
|
| 792 |
+
metrics.innerHTML = `
|
| 793 |
+
<div class="bg-gray-800/50 p-3 rounded-lg">
|
| 794 |
+
<div class="flex items-center justify-between">
|
| 795 |
+
<div class="font-medium flex items-center">
|
| 796 |
+
<i data-feather="shield" class="text-red-400 mr-2"></i>
|
| 797 |
+
<span>Security Analysis</span>
|
| 798 |
+
</div>
|
| 799 |
+
<span class="text-red-400 text-xs bg-red-400/10 px-2 py-0.5 rounded-full">3 risks</span>
|
| 800 |
+
</div>
|
| 801 |
+
<div class="mt-2 text-gray-400">
|
| 802 |
+
<p>• No input sanitization</p>
|
| 803 |
+
<p>• Potential type coercion issues</p>
|
| 804 |
+
<p>• No rate limiting protection</p>
|
| 805 |
+
</div>
|
| 806 |
+
</div>
|
| 807 |
+
<div class="bg-gray-800/50 p-3 rounded-lg">
|
| 808 |
+
<div class="flex items-center justify-between">
|
| 809 |
+
<div class="font-medium flex items-center">
|
| 810 |
+
<i data-feather="lock" class="text-green-400 mr-2"></i>
|
| 811 |
+
<span>Recommendations</span>
|
| 812 |
+
</div>
|
| 813 |
+
</div>
|
| 814 |
+
<div class="mt-2 text-gray-400">
|
| 815 |
+
<p>• Add input validation for array elements</p>
|
| 816 |
+
<p>• Implement proper error handling</p>
|
| 817 |
+
<p>• Consider using TypeScript</p>
|
| 818 |
+
</div>
|
| 819 |
+
</div>
|
| 820 |
+
`;
|
| 821 |
+
feather.replace();
|
| 822 |
+
}
|
| 823 |
+
|
| 824 |
+
function showBestPractices() {
|
| 825 |
+
const metrics = document.getElementById('analysisMetrics');
|
| 826 |
+
metrics.innerHTML = `
|
| 827 |
+
<div class="bg-gray-800/50 p-3 rounded-lg">
|
| 828 |
+
<div class="flex items-center justify-between">
|
| 829 |
+
<div class="font-medium flex items-center">
|
| 830 |
+
<i data-feather="award" class="text-yellow-400 mr-2"></i>
|
| 831 |
+
<span>Code Quality</span>
|
| 832 |
+
</div>
|
| 833 |
+
<span class="text-green-400 text-xs bg-green-400/10 px-2 py-0.5 rounded-full">85%</span>
|
| 834 |
+
</div>
|
| 835 |
+
<div class="mt-2 text-gray-400">
|
| 836 |
+
<p>• Good function naming</p>
|
| 837 |
+
<p>• Clear error handling</p>
|
| 838 |
+
<p>• Missing JSDoc comments</p>
|
| 839 |
+
</div>
|
| 840 |
+
</div>
|
| 841 |
+
<div class="bg-gray-800/50 p-3 rounded-lg">
|
| 842 |
+
<div class="flex items-center justify-between">
|
| 843 |
+
<div class="font-medium flex items-center">
|
| 844 |
+
<i data-feather="zap" class="text-blue-400 mr-2"></i>
|
| 845 |
+
<span>Optimizations</span>
|
| 846 |
+
</div>
|
| 847 |
+
</div>
|
| 848 |
+
<div class="mt-2 text-gray-400">
|
| 849 |
+
<p>• Use reduce() instead of forEach</p>
|
| 850 |
+
<p>• Add floating point precision</p>
|
| 851 |
+
<p>• Consider early returns</p>
|
| 852 |
+
</div>
|
| 853 |
+
</div>
|
| 854 |
+
`;
|
| 855 |
+
feather.replace();
|
| 856 |
+
}
|
| 857 |
+
</script>
|
| 858 |
|
| 859 |
<!-- CTA Section -->
|
| 860 |
<div class="bg-gradient-to-r from-primary/20 to-secondary/20 py-16 px-4 sm:px-6 lg:px-8">
|