-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from MikeBeloborodov/7_kyu_word_values
word values
- Loading branch information
Showing
5 changed files
with
22 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### Word values | ||
|
||
https://www.codewars.com/kata/598d91785d4ce3ec4f000018 | ||
|
||
![description](./description.jpg "Description") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { wordValue } from "./word_values"; | ||
|
||
describe("test cases", () => { | ||
it("should return [88, 12 225]", () => | ||
expect(wordValue(["codewars", "abc", "xyz"])).toStrictEqual([88, 12, 225])); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const wordValue = (a: string[]): number[] => | ||
a.map( | ||
(item, index) => | ||
(index + 1) * | ||
item | ||
.replace(/\s/g, "") | ||
.split("") | ||
.reduce((sum, val) => sum + val.charCodeAt(0) - 96, 0), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters