fn around(x: usize, y: usize) -> HashSet<(usize, usize)> {
return [
(Some(x), y.checked_add(1)),
(Some(x), y.checked_sub(1)),
(x.checked_add(1), Some(y)),
(x.checked_sub(1), Some(y)),
]
.iter()
.filter_map(|(vv, hh)| vv.and_then(|vvv| hh.and_then(|hhh| Some((vvv, hhh)))))
.collect();
}
// Add your tests here.
// See https://doc.rust-lang.org/stable/rust-by-example/testing/unit_testing.html
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_add() {
assert_eq!(
around(0, 1),
[(0, 2), (0, 0), (1, 1)].iter().cloned().collect()
);
assert_eq!(
around(1, 1),
[(1, 2), (1, 0), (2, 1), (0, 1)].iter().cloned().collect()
);
assert_eq!(
around(1, 0),
[(1, 1), (2, 0), (0, 0)].iter().cloned().collect()
);
assert_eq!(around(0, 0), [(1, 0), (0, 1)].iter().cloned().collect()); }
}
function returnhundred() { return (undefined +"")[2].charCodeAt(); }
- function returnhundred() {
return 10 ** 2;- return (undefined +"")[2].charCodeAt();
- }
// TODO: Add your tests here // Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework. // [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework) // are still available for now. // // For new tests, using [Chai](https://chaijs.com/) is recommended. // You can use it by requiring: // const assert = require("chai").assert; // If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted. describe("", () => { it("", () => { Test.assertEquals(returnhundred(),100) }) })
- // TODO: Add your tests here
- // Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
- // [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
- // are still available for now.
- //
- // For new tests, using [Chai](https://chaijs.com/) is recommended.
- // You can use it by requiring:
- // const assert = require("chai").assert;
- // If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.
Test.assertEquals(returnhundred(),100)- describe("", () => {
- it("", () => {
- Test.assertEquals(returnhundred(),100)
- })
- })