We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bbc58d5 commit 881ef40Copy full SHA for 881ef40
2288-apply-discount-to-prices.js
@@ -0,0 +1,16 @@
1
+/**
2
+ * @param {string} sentence
3
+ * @param {number} discount
4
+ * @return {string}
5
+ */
6
+var discountPrices = function(sentence, discount) {
7
+ const arr = sentence.split(' '), n = arr.length
8
+ for(let i = 0; i < n; i++) {
9
+ const cur = arr[i]
10
+ const rest = cur.slice(1)
11
+ if(cur.startsWith('$') && rest.length && !Number.isNaN(+rest)) {
12
+ arr[i] = '$' + ((+rest) * (100 - discount) / 100).toFixed(2)
13
+ }
14
15
+ return arr.join(' ')
16
+};
0 commit comments