Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Several approaches to converting values to lowercase not working

As part of a practice challenge for a bootcamp, I’ve been asked to: ‘Fix the jumbled string values – replace them all with versions that are all lowercase’

I’ve tried several approaches based on answers on SO as well as other sites online but they all seem to result in different errors. My code is passing all the other tests but won’t pass this one.

I’ve tried reducing, mapping, and as seen in the code below for-in loops; so not really sure where I’m going wrong.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

function sortTheKitchen(kitchen) {
    delete kitchen.hoover
    kitchen.totalShelves = (kitchen.shelvesInCupboards + kitchen.shelvesNotInCupboards) || kitchen.shelvesInCupboards || kitchen.shelvesNotInCupboards
    delete kitchen.shelvesInCupboards && delete kitchen.shelvesNotInCupboards
    for (let key in kitchen){
        let value = kitchen[key]
        if (typeof value === 'string'){
            value.toLowerCase()
        }
    }
    // Don't change the code below this line
    return kitchen;
}

>Solution :

As another answer stated, toLowerCase returns the modified string so you have to do:

value = value.toLowerCase()

instead of just:

value.toLowerCase()

if you want that line to do anything.

I’d suggest the whole thing to look something like:

function sortTheKitchen(kitchen) {
    delete kitchen.hoover
    kitchen.totalShelves = (kitchen.shelvesInCupboards + kitchen.shelvesNotInCupboards) || kitchen.shelvesInCupboards || kitchen.shelvesNotInCupboards
    delete kitchen.shelvesInCupboards && delete kitchen.shelvesNotInCupboards
    for (let key in kitchen){
        if (typeof kitchen[key] === 'string'){
            kitchen[key] = kitchen[key].toLowerCase()
        }
    }
    // Don't change the code below this line
    return kitchen;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading