[BOJ + Node.js] 1181: Word sort


// This question is asking me to do
// input words based on the length of each element
const input = require(‘fs’).readFileSync(‘/dev/stdin’).toString().split(‘\n’);let temp = [];
const num = Number(input[0]); // 13
let uniqueValues;
// make a ‘temp’ array
for(let i=1; i<= num; i++) {
temp.push(input[i]);
uniqueValues = new Set(temp)
}
let sortedArr = Array.from(uniqueValues)for(let i=0; i< sortedArr.length; i++) {
sortedArr.sort((a,b) => a.length-b.length || a.localeCompare(b))
}
console.log(sortedArr.join(‘\n’))// iterate through temp
// for(let i=0; i<temp.length; i++) {

// temp.sort(function(a,b) {
// a.length — b.length
// })
// }

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store