Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
Argument of type 'unknown' is not assignable to parameter of type 'string'." When I try to parse a stringified array

Sorry if this is a duplicate. I'm looking for the best way to convert an array into a key I can use for a set in JavaScript.

const set = new Set()
const arr = [1,0,-1]
const arr2 = [1,0,-1]
set.add(arr)
set.add(arr2)

This should work because both arr and arr2 are different objects and the set recognizes their references as unique. What's the best way I can convert arr and arr2 into keys so the set recognizes them as unique?

I tried doing JSON.stringify(arr), but I had difficulty converting them back into number[].

Any help is appreciated!

Here is the full version of the code I'm trying:

function twoSum(nums: number[], excludeIndex: number, target: number)
{
    let startPointer = 0;
    let endPointer = nums.length - 1;
    while(startPointer < endPointer)
    {
        if(startPointer === excludeIndex)
        {
            startPointer++;
        }
        if(endPointer === excludeIndex)
        {
            endPointer--;
        }
        if(nums[startPointer] + nums[endPointer] === target)
        {
            return [startPointer, endPointer]
        }
        if(nums[startPointer] + nums[endPointer] > target)
        {
            endPointer--;
        }
        else{
            startPointer++;
        }
    }
    return undefined
}

function threeSum(nums: number[]): number[][] {
    if(nums.length < 3)
    {
        return []
    }
    nums.sort((a,b) => a - b);
    let index = 0;
    const uniqueTriplets = new Set()
    while(index < nums.length)
    {
        const num = nums[index]
        const twoSumResult = twoSum(nums, index, (num * -1)) 
        if(twoSumResult !== undefined)
        {
            const triplet = [num, nums[twoSumResult[0]], nums[twoSumResult[1]]]
            triplet.sort((a,b) => a - b)
            uniqueTriplets.add(JSON.stringify(triplet))
        }
        index++;
    }

    return Array.from(uniqueTriplets.keys()).map(k => JSON.parse(k))
}

On the last return statement I get an error saying: "Argument of type 'unknown' is not assignable to parameter of type 'string'." When I add the JSON.parse(k)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!