DEV Community

Anjali Gurjar
Anjali Gurjar

Posted on

Solution

// function User(name){
// this.name=name

// };

// User.prototype.showName=function(){
// console.log(this.name)
// };
// function Student(branch,name){
// this.branch=branch
// this.proto= new User(name)

// };

// const student1=new Student("it","Anjali")

// student1.showName()
// const arr=[8, 4, 2, 1]
// const pairs=[]
// for(i=0;i // for(j=i+1;j // if(arr[i]>arr[j]){
// pairs.push([arr[i],arr[j]])
// }

// }
// }

// console.log("Inversion Pairs:", pairs);
// console.log("Number of Inversions:", pairs.length);

// const deeplyNested = [1, [2, [3, [4, [5]]]]];
// console.log(deeplyNested.flat(Infinity)); // [1, 2, 3, 4, 5]

// const arr= [1, 2, 3, 4, 5], k = 2

// const y=arr.slice(3,5).reverse()// start an d end with index number
// const
// console.log(y)

// const findMajorityElement = (arr) => {
// const majorityCount = Math.floor(arr.length / 2);

// for (let num of arr) {
// const count = arr.filter(x => x === num).length;
// if (count > majorityCount) {
// return num;
// }
// }

// return null; // No majority element
// };

// const arr = [3, 3, 4, 2, 4, 4, 2, 4, 4];
// console.log(findMajorityElement(arr)); // Output: 4

// const arr = [3, 4, 5, 1, 2];

// const isSortedAndRotated = (arr) => {
// let count = 0;
// const n = arr.length;

// for (let i = 0; i < n; i++) {
// // Check if current element is greater than the next (mod n for circular array)
// if (arr[i] > arr[(i + 1) % n]) {
// count++;
// }
// // If more than one inversion, return false
// if (count > 1) {
// return false;
// }
// }

// return count === 1; // Exactly one rotation
// };

// console.log(isSortedAndRotated(arr)); // Output: true

// non neagtive arr
// const arr = [1, 2, 3, 3, -3, -4, 7, -8];

// const removeNegatives = (arr) => {
// return arr.filter(num => num >= 0);
// };

// console.log(removeNegatives(arr)); // Output: [1, 2, 3, 3, 7]
sum of two number

var twoSum = function(nums, target) {
let sum=[]
for(let i=0;i<nums.length;i++){
for(let j=i+1;j<nums.length;j++){
if(nums[i]+nums[j]===target){
return [nums[i],nums[j]]

    }}
}
Enter fullscreen mode Exit fullscreen mode

}

    console.log(twoSum([1,23,4,5,52,7,2],9))
Enter fullscreen mode Exit fullscreen mode

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (2)

Collapse
 
anjali_gurjar_dff81513867 profile image
Anjali Gurjar •

function brackFormat(s){
const stack=[]
const string={
"}": "{",
"]": "[",
")": "("
}

 for(let char of s ){
     if (char === "{" || char === "[" || char === "(") {
            stack.push(char)
     }
     else if (char==="}"|| char==="]"|| char===")"){
         if(stack.pop()!==string[char]){
             return false

         }

      }


 }
     return stack.length === 0; 
Enter fullscreen mode Exit fullscreen mode

}

console.log(brackFormat("{[()]}"))

Collapse
 
anjali_gurjar_dff81513867 profile image
Anjali Gurjar •

const s ={"{[()]}" solve this question

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more