Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function lowestPrices (input) {
- let sales = new Map
- let lowerPrice = 0
- let currentTown = ''
- let towns = []
- let counter = 0
- let boolean = false
- for (let i = 0; i < input.length; i++) {
- let splitted = input[i].split(' | ')
- if (i == input.length - 1) {
- lowerPrice = Number(splitted[2])
- currentTown = splitted[0]
- sales.set(splitted[1], lowerPrice)
- towns.push(currentTown)
- }
- for (let j = i + 1; j < input.length; j++) {
- let splitted2 = input[j].split(' | ')
- if (splitted[1] == splitted2[1] && splitted[2] < splitted2[2] ) {
- lowerPrice = Number(splitted[2])
- currentTown = splitted[0]
- sales.set(splitted[1], lowerPrice)
- boolean = true
- }
- else if (splitted[1] == splitted2[1] && splitted[2] > splitted2[2]) {
- lowerPrice = Number(splitted2[2])
- currentTown = splitted2[0]
- sales.set(splitted[1], lowerPrice)
- boolean = true
- }
- }
- if (boolean == true)
- towns.push(currentTown)
- boolean = false
- }
- for (let [key,val] of sales) {
- console.log(key + ' -> ' + val + ' (' + towns[counter] + ')')
- counter++
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement