Skip to content

Commit 6fba612

Browse files
refactoring
1 parent 17ab715 commit 6fba612

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

6kyus/js/yourOrderPlease.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@
77
// filter out numbers
88
// add words of said numbers to key
99
// sort and assign words to sorted numbers
10-
function order(words) {}
10+
function order(words) {
11+
const wordKey = {}
12+
words.split(' ').map(ele => {
13+
// let num = ele.split('').filter(Number)
14+
// wordKey[num] = ele
1115

12-
console.log('is2 Thi1s T4est 3a', 'the answer is: ', 'Thi1s is2 3a T4est')
13-
console.log('4of Fo1r pe6ople g3ood th5e the2', 'the answer is: ', 'Fo1r the2 g3ood 4of th5e pe6ople')
14-
console.log('', 'the answer is: ', '', 'empty input should return empty string')
15-
console.log(words())
16+
wordKey[ele.split('').filter(Number)] = ele
17+
})
18+
return Object.values(wordKey).join(' ')
19+
}
20+
21+
console.log(order('is2 Thi1s T4est 3a'), 'the answer is: ', 'Thi1s is2 3a T4est')
22+
console.log(order('4of Fo1r pe6ople g3ood th5e the2'), 'the answer is: ', 'Fo1r the2 g3ood 4of th5e pe6ople')
23+
console.log(order(''), 'the answer is: ', '', 'empty input should return empty string')

0 commit comments

Comments
 (0)